DataFrame.toExcel

Converts a DataFrame or Series to Excel file and write file to disk or download in browser.

Deprecated in v1.1.0: Use the dfd.toExcel function directly instead

DataFrame.toExcel(options)

The toExcel function can be used to write out a DataFrame or Series to Excel (.xlsx) file. The output format will depend on the environment. In the following examples, we show you how to write/download an Excel file from Node and Browser environments.

Convert DataFrame to Excel and write to file path

Writing an Excel file to a local file path is only supported in the Nodejs environment

const dfd = require("danfojs-node")

let data = {
    Abs: [20.2, 30, 47.3],
    Count: [34, 4, 5],
    "country code": ["NG", "FR", "GH"],
};

let df = new dfd.DataFrame(data);

df.toExcel({ filePath: "testOut.xlsx"});

Convert DataFrame to Excel and download the file in a browser

You can automatically convert and download an Excel file in a browser environment, by specifying a fileName.

let data = {
    Abs: [20.2, 30, 47.3],
    Count: [34, 4, 5],
    "country code": ["NG", "FR", "GH"],
};

let df = new dfd.DataFrame(data);

df.toExcel({ fileName: "testOut.xlsx", download: true });

Last updated