10 python ipython python-import python-2.7 pandas
子模块不是隐式导入的,必须显式声明,但我正在对子模块进行显式调用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"])
Run Code Online (Sandbox Code Playgroud)
结果是:
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'
Run Code Online (Sandbox Code Playgroud)
我哪里出错了?