pandas AttributeError: 模块对象没有属性“系列”。代码在 iPython 中工作

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

AttributeError: module object has no attribute "Series". Code works in iPython

pythonpython-2.7pandasipythonpython-import

提问by Phillip Cloud

Submodules aren't implicitlyimported, and must be explicitlydeclared, but I'm making an explicitcall to the pd.Seriessubmodule, aren't I?

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

Regardless, shouldn't import pandas as pdallow for pd.Seriesto be called? The following code works flawlessly in iPython, but fails when executed from a script.

无论如何,不​​应该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"])

Results in:

结果是:

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'

Where have I gone wrong?

我哪里错了?

回答by Phillip Cloud

The issue is that you've called your module pandas. Call it something else. And don't forget to delete the pandas.pycgenerated on import pandasor else it will keep failing.

问题是您已经调用了 module pandas。叫它别的东西。并且不要忘记删除pandas.pyc生成的,import pandas否则它会一直失败。

回答by S.Bao

I had to same issue with the error message "'module' object has no attribute '_tseries'", I have missed to install python-dateutilpackage

我遇到了与错误消息“'module'对象没有属性'_tseries'”相同的问题,我错过了安装python-dateutil

The solution:

解决方案:

with python2.6, to install pandas 0.6.1, you have to install numpy 1.6.1 and python-dateutil like 2.6.1

使用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

Good luck ;)

祝你好运 ;)

回答by janicebaratheon

the file name cannot be called pandas.py

文件名不能叫pandas.py

回答by Mike

series in ipython not python

ipython 中的系列不是 python

try 

  $ ipython
  import pandas as pd
  import numpy as np

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