Python 模块“pandas”没有属性“read_csv”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40554657/
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-08-19 23:39:22  来源:igfitidea点击:

module 'pandas' has no attribute 'read_csv

pythoncsvnumpy

提问by Willstarr

import pandas as pd

df = pd.read_csv('FBI-CRIME11.csv')

print(df.head())

Running this simple code gives me the error:

运行这个简单的代码给了我错误:

Traceback (most recent call last):
  File "C:/Users/Dita/Desktop/python/lessons/python.data/csv.py", line 1, in <module>
    import pandas as pd
  File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\__init__.py", line 37, in <module>
    import pandas.core.config_init
  File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\core\config_init.py", line 18, in <module>
    from pandas.formats.format import detect_console_encoding
  File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\formats\format.py", line 33, in <module>
    from pandas.io.common import _get_handle, UnicodeWriter, _expand_user
  File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\io\common.py", line 5, in <module>
    import csv
  File "C:\Users\Dita\Desktop\python\lessons\python.data\csv.py", line 4, in <module>
    df = pd.read_csv('FBI-CRIME11.csv')
AttributeError: module 'pandas' has no attribute 'read_csv'

回答by AKX

Try renaming your csv.pyto something else, like csv_test.py. Looks like pandasis being confused about what to import.

尝试将您的重命名csv.py为其他名称,例如csv_test.py. 看起来pandas对要导入的内容感到困惑。

回答by Atul Balaji

I had checked for the presence of csv.pyand made sure there was no file of this name. I also tried pip uninstall pandasand then pip install pandas. I still got the same error.

我检查了存在csv.py并确保没有这个名字的文件。我也试过pip uninstall pandas然后pip install pandas。我仍然遇到同样的错误。

What worked for me was: pip-autoremove.

什么工作对我来说是:pip-autoremove

First install it using pip install pip-autoremove.
Then, remove pandas using pip-autoremove pandas -y.
Next, reinstall it using pip install pandas.

首先使用pip install pip-autoremove.
然后,使用pip-autoremove pandas -y.
接下来,使用 重新安装它pip install pandas

The reason why this is necessary is that sometimes, when using uninstall, the package folder may still be present.

之所以需要这样做,是因为有时在使用卸载时,包文件夹可能仍然存在。