pandas 'DataFrame' 对象没有属性 'read_csv'

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34087903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 00:19:45  来源:igfitidea点击:

'DataFrame' object has no attribute 'read_csv'

pythonpandas

提问by EnduroDave

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

与此非常相似的问题(在 pandas python 中没有名为 read_csv 的属性),但解决方案对我不起作用。

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

我尝试添加,reload(pd)但这没有帮助。工作目录中也没有 pandas.py 或 pyc

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'

采纳答案by ASGM

Try this:

尝试这个:

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

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

错误是正确的:read_csv不是 a 的属性DataFrame。这是Pandas本身的一种方法:read_csv. 您的问题和另一个问题之间的区别在于,他们正确地调用了它(作为pandas.read_csvpd.read_csv),而您将其称为数据框的一个属性。