Skip to content

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

@kburchfiel

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions