10

子模块不是隐式导入的,必须显式声明,但我正在显式调用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'

我哪里出错了?

4

3 回答 3

22

问题是您已经调用了您的模块pandas。叫它别的东西。并且不要忘记删除pandas.pyc生成的 onimport pandas否则它将继续失败。

于 2013-08-18T03:18:28.663 回答
0

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

解决方案:

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

pip install numpy==1.6.1
pip install python-dateutil==2.6.1
pip install --force-reinstall pandas==0.6.1
于 2018-04-12T16:04:43.943 回答
0

ipython中的系列不是python

try 

  $ ipython
  import pandas as pd
  import numpy as np

  counts = pd.Series([632, 1638, 569, 115], index=["Firmicutes", "Proteobacteria", "Actinobacteria", "Bacteroidetes"])
于 2018-02-14T19:11:57.787 回答