2
$\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$

3 Answers 3

8
$\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.

$\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")
$\endgroup$
0
$\begingroup$

pd.read_csv is used to read a csv file, you are trying to make a dictionary into a dataframe, use pd.DataFrame() function for this.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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