简体   繁体   English

AttributeError:部分初始化的模块“pandas”没有属性“DataFrame”

[英]AttributeError: partially initialized module 'pandas' has no attribute 'DataFrame'

i want to run this code but i can't and received this error.我想运行此代码,但我不能并收到此错误。 also i downloaded pandas package.我还下载了 pandas package。

import pandas

data = {
    "Day": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    "Visitors": [18, 26, 18, 18, 9, 9, 20, 30, 16, 24],
    "Bounce_Rate": [77.27, 74.07, 73.68, 65, 90, 70, 72, 62.16, 81.25, 72],
}

df = pandas.DataFrame(data)
print(df)

Have you have saved your file as pandas.py ?您是否已将文件保存为pandas.py It will confuse the namespace if the file is named pandas.py Otherwise check if there is any file named pandas and delete it.如果文件名为pandas.py则会混淆命名空间,否则检查是否存在名为 pandas 的文件并将其删除。 So that you can definitely succeed in fixing this.这样您绝对可以成功解决此问题。

If you are getting an attribute error, this means the program is not recognizing the pandas library.如果您收到属性错误,这意味着程序无法识别 pandas 库。 Is there another variable you named pandas?您是否还有另一个变量命名为 pandas? Or a directory or file you have named pandas?或者您命名为 pandas 的目录或文件?

Most likely, the name of your python script was 'pandas.py' which will cause a circular import...最有可能的是,您的 python 脚本的名称是“pandas.py”,这将导致循环导入......

AttributeError: partially initialized module 'pandas' has no attribute 'DataFrame' (most likely due to a circular import)

I've also seen this error.我也看到了这个错误。 My solution and causes were different than others mentioned, so I'll offer info below.我的解决方案和原因与其他提到的不同,所以我将在下面提供信息。

  1. I was running a cell in a jupyter notebook (filename not pandas.py but 0_isbn_get.ipynb)我在 jupyter 笔记本中运行一个单元(文件名不是 pandas.py 而是 0_isbn_get.ipynb)
  2. I hadn't yet activated my virtual environment我还没有激活我的虚拟环境
  3. Starting the virtual environment then running the cell did not fix the issue启动虚拟环境然后运行单元没有解决问题

Fix:使固定:

  1. Restart the kernel重启 kernel
  2. activate the virtual environment激活虚拟环境
  3. Run the notebook cell运行笔记本单元

please check your panda version reinstall panda in colab restart runtime and run all请检查您的熊猫版本在 colab 重新启动运行时重新安装熊猫并运行所有

SORRY FOR MY ENGLISH.对不起我的英语不好。 I'M LEARNING.我在学。

In my case, I solved the error by changing the file name.就我而言,我通过更改文件名解决了错误。

# in file: csv.py 
import pandas as pd
data = {'first_name': ['Sigrid', 'Joe', 'Theodoric','Kennedy', 'Beatrix', 'Olimpia', 'Grange', 'Sallee'],
        'last_name': ['Mannock', 'Hinners', 'Rivers', 'Donnell', 'Parlett', 'Guenther', 'Douce', 'Johnstone'],
        'age': [27, 31, 36, 53, 48, 36, 40, 34],
        'amount_1': [7.17, 1.90, 1.11, 1.41, 6.69, 4.62, 1.01, 4.88],
        'amount_2': [8.06,  "?", 5.90,  "?",  "?", 7.48, 4.37,  "?"]}
datosDataFrame = pd.DataFrame(data)
print(datosDataFrame)
datosDataFrame.to_csv('example.csv')

I get an error我收到一个错误

Error: AttributeError partially initialized module 'pandas' has no 
attribute 'DataFrame' (most likely due to a circular import)

"Most likely due to a circular import" means any variable/name is repeated. “很可能是由于循环导入”意味着重复任何变量/名称。 In my case, my script csv.py conflicted with csv in the standard library.就我而言,我的脚本csv.py与标准库中的csv冲突。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python/Json AttributeError:部分初始化的模块“json”没有属性 - Python/Json AttributeError: partially initialized module 'json' has no attribute 不断收到这个 AttributeError:部分初始化的模块 'schedule' 没有属性 'every' - Keep getting this AttributeError: partially initialized module 'schedule' has no attribute 'every' attributererror: 部分初始化的模块“turtle”没有属性“bgcolor” - attributeerror: partially initialized module 'turtle' has no attribute 'bgcolor' 部分初始化的模块“pandas”没有属性“read_csv” - Partially initialized module 'pandas' has no attribute 'read_csv' AttributeError:部分初始化的模块“pandas”没有属性“read_csv”(很可能是由于循环导入)。 我如何解决它? - AttributeError: partially initialized module 'pandas' has no attribute 'read_csv' (most likely due to a circular import). How do I fix it? data = pandas.read_excel('filename.xlsx' 不起作用。得到一个错误:AttributeError: 部分初始化的模块 'pandas' 没有属性 - data = pandas.read_excel('filename.xlsx' doesn't work. Get an error: AttributeError: partially initialized module 'pandas' has no attribute AttributeError: 部分初始化的模块“juego”没有属性“VENTANA_VERTICAL”(很可能是由于循环导入) - AttributeError: partially initialized module 'juego' has no attribute 'VENTANA_VERTICAL' (most likely due to a circular import) AttributeError: 部分初始化的模块“sympy”没有属性“S”(很可能是由于循环导入) - AttributeError: partially initialized module 'sympy' has no attribute 'S' (most likely due to a circular import) AttributeError: 部分初始化的模块“folium”没有属性“Map”(很可能是由于循环导入) - AttributeError: partially initialized module 'folium' has no attribute 'Map' (most likely due to a circular import) AttributeError:部分初始化的模块'pims'没有属性'pyav_reader'很可能是由于循环导入) - AttributeError: partially initialized module 'pims' has no attribute 'pyav_reader' most likely due to a circular import)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM