AttributeError: 模块 'pandas' 没有属性 'read_csv' Python3.5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43696005/
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
AttributeError: module 'pandas' has no attribute 'read_csv' Python3.5
提问by muazfaiz
I have been successfully using pandas.read_csv
since long but suddenly it starts giving the error while I try to read a csv file
我pandas.read_csv
长期以来一直在成功使用,但在我尝试读取 csv 文件时突然开始出现错误
df = pd.read_csv('file.csv', encoding='utf-8')
The error is
错误是
AttributeError: module 'pandas' has no attribute 'read_csv'
I have tried to upgrade pandas but does not work. I tried to search and got this answerbut when I search csv.py file in my pandas I didn't find any. So i tried to hover over the pandas.read_csv
method which takes me to parsers.py
file. But in that file there is no specific method named read_csv
but it directed to another parser funtion like this
我曾尝试升级熊猫,但不起作用。我试图搜索并得到了这个答案,但是当我在我的 Pandas 中搜索 csv.py 文件时,我没有找到任何。所以我试图将鼠标悬停在pandas.read_csv
带我提交parsers.py
文件的方法上。但是在该文件中没有命名的特定方法,read_csv
但它指向另一个像这样的解析器功能
# parser.py (built-in file in pandas) file has this implementation
read_csv = _make_parser_function('read_csv', sep=',')
read_csv = Appender(_read_csv_doc)(read_csv)
I don't understand how should it start working again ? Any suggestions
我不明白它应该如何重新开始工作?有什么建议
回答by Drew
I had the same problem when trying to run the following code in Jupyter/ipython.
尝试在 Jupyter/ipython 中运行以下代码时遇到了同样的问题。
import pandas as pd
df = pd.read_csv("weather_data.csv")
df
I realized I had a file named pandas.py. In fact, had two others named pandas1.py and pandas2.py as well. I changed them all and then it worked perfectly:) Lesson learned.
我意识到我有一个名为 pandas.py 的文件。事实上,还有另外两个名为 pandas1.py 和 pandas2.py 的。我把它们都改了,然后它就完美运行了:) 吸取了教训。
回答by muazfaiz
So I am writing an answer myself. I just noticed that I created a file random.py
in my project which was creating a conflict with random.py
in pandas
package. Renaming my current file to something else worked for me :)
所以我自己写了一个答案。我只注意到我创建了一个文件random.py
在我的项目这是创建与冲突random.py
的pandas
包。将我当前的文件重命名为其他对我有用的文件:)
回答by Simon.Hermit
I faced the same problem and the solution that worked for me is as below.
我遇到了同样的问题,对我有用的解决方案如下。
Initially I installed the pandas and numpy with a regular user account. It installed library but there were few conflicts. So I uninstalled the libraries using pip uninstall package
then installed them back as sudo account using sudo -H pip install package
.
最初,我使用普通用户帐户安装了 pandas 和 numpy。它安装了库,但几乎没有冲突。所以我卸载了这些库,pip uninstall package
然后使用sudo -H pip install package
.
I hope it helps other people facing similar issue.
我希望它可以帮助其他面临类似问题的人。
回答by ColdAbsurdism
You literally just need to make sure that you have no ".py" files that have names of the same names of the packages. Like pandas.py, numpy.py etc..
您实际上只需要确保没有与包名称相同的“.py”文件。像 pandas.py、numpy.py 等。
回答by Anirban Hymany
Put your csv file in the directory or folder where your python project files are . This solution worked for me.
将您的 csv 文件放在您的 python 项目文件所在的目录或文件夹中。这个解决方案对我有用。