AttributeError: module object has no attribute “Series”. Code works in Python

 

 
 

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'



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.
很容易忽视,文件的命名和我们所调用的包是一样的名字。所以会导致原本的包里面的函数找不到!!!
本文转自https://stackoverflow.com/questions/18295314/attributeerror-module-object-has-no-attribute-series-code-works-in-ipython
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值