I don't seem to be able to call Series.get on a Series object.
>> print col
0 1
1 1
2 0
Name: a, dtype: float64
>>> counts = col.value_counts()
>>> print counts
1 2
0 1
dtype: int64
... makes sense. 2 ones. 1 zero
>>> print type(counts)
<class 'pandas.core.series.Series'>
... OK. The result is a Series. How can I read out the elements? According to Series.get , and the docstring for counts.get, I should be able to:
zeros = counts.get(0,0)
ones = counts.get(1,0)
... but this fails with:
AttributeError: 'numpy.ndarray' object has no attribute 'values'
What I have misunderstood?
>>> 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
In:
>>> print counts
1 2
0 1
aren't 1 and 0 the labels?
Seems to be bug in pandas 15
Upgrading to pandas 18 resolves this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.