【问题标题】:AttributeError: module object has no attribute "Series". Code works in iPythonAttributeError:模块对象没有属性“系列”。代码在 iPython 中工作
【发布时间】:2013-08-20 03:48:29
【问题描述】:

子模块不是隐式导入的,必须显式声明,但我正在显式调用pd.Series子模块,不是吗?

无论如何,import pandas as pd 不应该允许调用pd.Series 吗?以下代码在 iPython 中完美运行,但从脚本执行时失败。

#!/usr/bin/env/python2.7
# -*- coding: utf-8 -*-
import pandas as pd
import numpy as np

counts = pd.Series([632, 1638, 569, 115], index=["Firmicutes", "Proteobacteria", "Actinobacteria", "Bacteroidetes"])

结果:

tyler@machine ~/src/stats $ python pandas.py
Traceback (most recent call last):
  File "pandas.py", line 3, in <module>
    import pandas as pd
  File "/home/tyler/src/stats/pandas.py", line 6, in <module>
    counts = pd.Series([632, 1638, 569, 115], index=["Firmicutes", "Proteobacteria", "Actinobacteria", "Bacteroidetes"])
AttributeError: 'module' object has no attribute 'Series'

我哪里出错了?

【问题讨论】:

    标签: python python-2.7 pandas ipython python-import


    【解决方案1】:

    我对错误消息'module' object has no attribute '_tseries' 有同样的问题,我错过了安装python-dateutil 包。

    解决办法:

    使用 python2.6,要安装 pandas 0.6.1,您必须安装 numpy 1.6.1 和 python-dateutil,如 2.6.1:

    pip install numpy==1.6.1
    pip install python-dateutil==2.6.1
    pip install --force-reinstall pandas==0.6.1
    

    【讨论】:

      【解决方案2】:

      ipython 不是 python 中的系列

      try 
      
        $ ipython
        import pandas as pd
        import numpy as np
      
        counts = pd.Series([632, 1638, 569, 115], index=["Firmicutes", "Proteobacteria", "Actinobacteria", "Bacteroidetes"])
      

      【讨论】:

      • 欢迎来到stackoverflow!仅代码答案很有帮助,但添加解释会更有帮助。
      【解决方案3】:

      问题是您已将模块称为pandas。叫它别的东西。并且不要忘记删除在import pandas 上生成的pandas.pyc,否则它会一直失败。

      【讨论】:

      • 请注意,这似乎只是 Python 2.7.x 中的问题,而不是 3.x 中的问题。
      猜你喜欢
      • 1970-01-01
      • 2012-06-02
      • 2015-06-24
      • 1970-01-01
      • 2010-11-18
      相关资源
      最近更新 更多