danfo.readExcel

Reads a JSON file from local or remote location into a DataFrame.

danfo.readExcel(source, options)

ParametersTypeDescription

source

string

source : string, URL or local file path to Excel file.

options

Object

{

sheet : string, (Optional) Name of the sheet which u want to parse. Default will be the first sheet. method: The HTTP method to use.

headers: Additional headers to send with the request if reading JSON from remote url. Supports all the node-fetch options in Nodejs, and all fetch options in browsers.

frameConfig: Optional arguments passed when creating the DataFrame. e.g column names, index. etc.

parsingOptions: supports all xlsx options. See https://docs.sheetjs.com/docs/api/parse-options

}

Example

The readExcel method can read excel files saved on a local disk, or over the internet.

const dfd = require("danfojs-node")
const path = require("path")

let local_xcel = path.join(process.cwd(), "data", "testexcel.xlxs")

async function load_process_data() {
    let df = await dfd.readExcel(local_xcel)
    df.head().print()
}

load_process_data()

Reading an input file object in the browser

By specifying a valid file object, you can load Excel files in the browser in DataFrames/Series

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
     <script src="https://cdn.jsdelivr.net/npm/danfojs@1.1.2/lib/bundle.min.js"></script>
    <title>Document</title>
</head>

<body>
    <input type="file" id="file" name="file">
    <script>
        const inputFile = document.querySelector('#file')
        
        inputFile.addEventListener("change", async () => {
            const excelFile = inputFile.files[0]
            dfd.readExcel(excelFile).then((df) => {
                df.print()
            })
        })
         
    </script>
</body>

</html>

Last updated