【问题标题】:Getting 'module' object has no attribute 'Series' when pandas installed安装熊猫时获取“模块”对象没有属性“系列”
【发布时间】:2018-04-12 21:17:07
【问题描述】:

我希望能够在我的计算机上使用 Pandas 来处理数据。我已经能够在 iPython 笔记本中做到这一点。但是在我的电脑上,当我尝试使用 Pandas 中的任何东西时,我得到以下信息:

Traceback (most recent call last):
  File "/Users/Desktop/pandas.py", line 1, in <module>
    import pandas as pd
  File "/Users/Desktop/pandas.py", line 7, in <module>
    s = pd.Series([1,3,5,np.nan,6,8])
AttributeError: 'module' object has no attribute 'Series'
[Finished in 0.1s with exit code 1]

我已检查以确保我的计算机上安装了 pandas。当我运行pip install pandas 时,我得到:

Requirement already satisfied (use --upgrade to upgrade): pandas in /anaconda/lib/python2.7/site-packages
Requirement already satisfied (use --upgrade to upgrade): python-dateutil in /anaconda/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): pytz>=2011k in /anaconda/lib/python2.7/site-packages (from pandas)
Requirement already satisfied (use --upgrade to upgrade): numpy>=1.6.1 in /anaconda/lib/python2.7/site-packages (from pandas)
Cleaning up...

这似乎表明已经安装了pandas。

【问题讨论】:

  • 看起来您正在尝试在桌面目录中运行一个脚本,并且在同一个地方还有另一个名为 pandas.py 的脚本。如果是这种情况,那么您的导入语句正在导入 /Users/Desktop/pandas.py 而不是 pandas 库。
  • 就是这样。我删除了文件。当我现在尝试运行时,它只是说“没有名为 pandas 的模块”。知道导致这种情况的错误是什么吗?我检查了我是否安装了 pandas。
  • 您的桌面上是否还有pandas.pyc 文件?
  • 我删除了那个,但把它移回了桌面。不知道那是为了什么...现在阅读...
  • 另外,你可以通过pd.__file__查看正在使用的文件,正如其他人所说,调用与另一个模块同名的文件是麻烦的。

标签: python pandas


【解决方案1】:

您是否检查过您使用的是什么版本的 python?看来您在 python27 中安装了 pandas。是否也来自用 python27 编写的脚本的回溯?如果不是,那将导致问题。

这个问题的答案很好解释:Installed Python Modules - Python can't find them

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-21
    • 1970-01-01
    • 2019-02-28
    • 2021-09-26
    • 2017-03-26
    • 2014-05-05
    • 1970-01-01
    相关资源
    最近更新 更多