Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'DataFrame' object has no attribute 'read_csv'

Tags:

python

pandas

Very similar question to this (no attribute named read_csv in pandas python) but the solutions are not working for me.

Very simple code thats not working

import numpy as np
import pandas as pd

df = pd.DataFrame()
df.read_csv('flexibility user survey.csv')

I tried adding reload(pd) but that didn't help. No pandas.py or pyc in the working directory either

full error just in case it helps

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-57-5c55472122b4> in <module>()
     12 
     13 df = pd.DataFrame()
---> 14 df.read_csv('flexibility user survey.csv')

/Users/davidpier/anaconda/lib/python2.7/site-packages/pandas/core/generic.pyc in __getattr__(self, name)
   1945                 return self[name]
   1946             raise AttributeError("'%s' object has no attribute '%s'" %
-> 1947                                  (type(self).__name__, name))
   1948 
   1949     def __setattr__(self, name, value):

AttributeError: 'DataFrame' object has no attribute 'read_csv'
like image 923
EnduroDave Avatar asked Mar 13 '23 23:03

EnduroDave


1 Answers

Try this:

df = pd.read_csv('flexibility user survey.csv')

The error's right: read_csv isn't an attribute of a DataFrame. It's a method of pandas itself: pandas.read_csv. The difference between your question and the other one is that they're calling it properly (as pandas.read_csv or pd.read_csv) and you're calling it as if it were an attribute of your dataframe (as df.read_csv).

like image 102
ASGM Avatar answered Mar 24 '23 20:03

ASGM