pandas 导入错误:无法导入名称 DataFrame

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

ImportError: cannot import name DataFrame

pythonpandas

提问by kevbuntu

I am using Pandas for the first time and trying to import Pandas, DataFrameand pandas.io.dataas such

我使用的大Pandas首次与尝试导入大Pandas,DataFramepandas.io.data为这样的

import pandas as pd
from pandas import DataFrame
import pandas.io.data

I get the error

我收到错误

"ImportError: cannot import name DataFrame"

“导入错误:无法导入名称数据帧”

and

"ImportError: No module named io.data"

“导入错误:没有名为 io.data 的模块”

I have tried the following to find the source of error on Ubuntu 14.04:

我尝试了以下方法来查找 Ubuntu 14.04 上的错误来源:

$pip show pandas
-> Version: 0.14.0
Location: /home/new-pc/anaconda/lib/python2.7/site-packages
$$PATH
-> bash: /home/new-pc/anaconda/bin

Not sure where else to look for errors. Thanks for all the inputs.

不知道还能在哪里查找错误。感谢您的所有投入。

回答by Guillaume Jacquenot

You must be mixing Python installations, with several pythonprograms/distributions (Anaconda), and maybe python version (2 and 3)

您必须将 Python 安装与多个python程序/发行版 (Anaconda) 以及 Python 版本(2 和 3)混合使用

The following commands should not produce any error:

以下命令不应产生任何错误:

sudo apt-get install python
sudo pip install pandas
python -c'import pandas as pd; from pandas import DataFrame; import pandas.io.data'

回答by Wiktor Stribi?ew

It will happen if you call your file pandas.pyand try to run it. You should rename the file then.

如果您调用文件pandas.py并尝试运行它,就会发生这种情况。然后你应该重命名文件。

It will also occur if you save a pandas.pyfile in the Python directory. Check if you have any files called pandas.pythere and rename/move those files to another location.

如果将pandas.py文件保存在 Python 目录中,也会发生这种情况。检查您是否在pandas.py那里调用了任何文件并将这些文件重命名/移动到另一个位置。

回答by rearThing

Try:

尝试:

from pandas_datareader import data

as shown in the example here

如图中示例这里

回答by Dexter

Check if you have saved any file with same names as in pandas libraries, such as saving file name as DataFrame.py. Always avoid naming the program as same as library name check all the location.Once you remove/rename your python script will run without any issue.

检查您是否保存了与pandas库中同名的文件,例如将文件名保存为DataFrame.py。始终避免将程序命名为与库名称相同的检查所有位置。一旦您删除/重命名您的python 脚本将毫无问题地运行。