Skip to content

How can I read a CSV file into a persistent DataFrame that can be used later in my script? #686

Open

Description

@kburchfiel

I am trying to read a CSV file into a DataFrame that I can use later in my code for a Leaflet map. Based on the Danfo.js documentation, here's what my code currently looks like:

dfd.readCSV("my_online_csv_file.csv")
.then(df => {
    df.describe().print()

}).catch(err => {
    console.log(err);
})

This code does indeed output some descriptive stats within my console. However, if I then try to access this DataFrame outside this block via df.head().print();, I get the following error:

Uncaught ReferenceError: df is not defined

I also tried the following setup:

df_data = dfd.readCSV("my_online_csv_file.csv");
df.head().print()

However, this produced the following error:

Uncaught TypeError: df.head is not a function

Is there an easy way for me to both read in a CSV file and access in later in the function? As a newcomer to both JavaScript and Danfo, I feel like I'm missing something very obvious.

Activity

  1. kburchfiel commented on Jan 8, 2026

    @kburchfiel
    Author

    I now realize that one workaround is to use Pandas to export my data to a .json file (with orient = records specified in to_json()); copy and paste this .json data into my code editor; specify it as a variable; and then run df = new dfd.DataFrame(state_json_data) as specified in the quickstart. This setup allows me to get the expected result when I call df.head(5).print().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions