AttributeError: module object has no attribute “Se

2019-06-15 19:12发布

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?

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"])

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?

3条回答
放荡不羁爱自由
2楼-- · 2019-06-15 19:28

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.

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-06-15 19:31

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

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

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

Good luck ;)

查看更多
干净又极端
4楼-- · 2019-06-15 19:51

series in ipython not python

try 

  $ ipython
  import pandas as pd
  import numpy as np

  counts = pd.Series([632, 1638, 569, 115], index=["Firmicutes", "Proteobacteria", "Actinobacteria", "Bacteroidetes"])
查看更多
登录 后发表回答