简体   繁体   中英

'DataFrame' object has no attribute 'read_csv'

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'

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 ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM