AttributeError:模块对象没有属性“Series”。代码适用于iPython [英] AttributeError: module object has no attribute "Series". Code works in iPython
问题描述
子模块不是隐式导入的,必须显式声明,但我正在对<$ c进行显式调用$ c> pd.Series 子模块,不是我吗?
Submodules aren't implicitly imported, and must be explicitly declared, but I'm making an explicit call to the pd.Series
submodule, aren't I?
无论如何,不应该将pandas导入为pd
允许调用 pd.Series
?以下代码在 iPython 中完美运行,但在从脚本执行时失败。
Regardless, shouldn't import pandas as pd
allow for pd.Series
to be called? The following code works flawlessly in iPython, but fails when executed from a script.
#!/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'
我哪里出错?
推荐答案
问题是你已经调用了你的模块 pandas
。称之为别的东西。并且不要忘记删除在导入pandas
上生成的 pandas.pyc
,否则它将继续失败。
The issue is that you've called your module pandas
. Call it something else. And don't forget to delete the pandas.pyc
generated on import pandas
or else it will keep failing.
这篇关于AttributeError:模块对象没有属性“Series”。代码适用于iPython的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!