2016-09-20 84 views
0

我似乎无法在Series对象上调用Series.get。pandas.Series.get失败,对象没有属性值'

>> print col 
0 1 
1 1 
2 0 
Name: a, dtype: float64 
>>> counts = col.value_counts() 
>>> print counts 
1 2 
0 1 
dtype: int64 

...有道理。 2个。 1零

>>> print type(counts) 
<class 'pandas.core.series.Series'> 

...好的。结果是一个系列。我怎样才能读出这些元素?据Series.get,并counts.get文档字符串,我应该能够:

zeros = counts.get(0,0) 
ones = counts.get(1,0) 

...但这个失败:

AttributeError: 'numpy.ndarray' object has no attribute 'values' 

我误会了?

>>> help(counts.get) 
Help on method get in module pandas.core.series: 

get(self, label, default=None) method of pandas.core.series.Series instance 
    Returns value occupying requested label, default to specified 
    missing value if not present. Analogous to dict.get 

    Parameters 
    ---------- 
    label : object 
     Label value looking for 
    default : object, optional 
     Value to return if label not in index 

    Returns 
    ------- 
    y : scalar 

在:

>>> print counts 
1 2 
0 1 

不是1个0的标签?

+0

不能在python 3.5.2,pandas 0.18.1中重现你的问题。 – Psidom

+0

我都没有---似乎是在最新版本中修复的。 – user48956

回答

0

好像是错误的熊猫15

升级到大熊猫18解决此问题。