1
$\begingroup$

I'm trying to create some charts using Python. I've this dataset in a CSV file:

Banana  Water   Rice
Rice    Water
Bread   Banana  Juice 

And I've this code:

 import numpy as np
    from pandas import DataFrame
    import matplotlib
    matplotlib.use('agg') # Write figure to disk instead of displaying (for Windows Subsystem for Linux)
    import matplotlib.pyplot as plt

    data = DataFrame.read_csv("test.csv", index_col=1, skiprows=1).T.to_dict()

But when I execute the code I'm getting the following error:

AttributeError: type object 'DataFrame' has no attribute 'read_csv'

How can I solve this problem?

Many thanks!

$\endgroup$
5
$\begingroup$

read_csv() is not available on DataFrame. to read csvs using pandas -

import pandas as pd
data = pd.read_csv("file_name")

if you check type(data), it will be pandas DataFrame.

| improve this answer | |
$\endgroup$
1
$\begingroup$

For reading data from csv you can use pd.read_csv or pd.read_table. Example:

Import pandas as pd

data = pd.read_csv("file_name")
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.