user3085496
user3085496

Reputation: 205

How to take one part of a Series in Pandas?

How do I only take the values on the right? Ex. only have an array/list of [120, 108, 82...]

d = daily_counts.loc[daily_counts['workingday'] == "yes", 'casual']
d

enter image description here

Upvotes: 1

Views: 353

Answers (1)

Grayrigel
Grayrigel

Reputation: 3594

You can simply use tolist() or values or to_numpy method. Here is a toy example:

>>> df = pd.DataFrame({'a':[1,2,3,4,5,7,1,4]})
>>>    
   a
0  1
1  2
2  3
3  4
4  5
5  7
6  1
7  4

>>> df['a'].value_counts() #generates similar output as you
>>> 
4    2
1    2
7    1
5    1
3    1
2    1
Name: a, dtype: int64

>>> df['a'].value_counts().tolist() #extracting as a list
[2, 2, 1, 1, 1, 1]

>>> df['a'].value_counts().values #extracting as a numpy array
array([2, 2, 1, 1, 1, 1])

>>> df['a'].value_counts().to_numpy() #extracting as a numpy array
array([2, 2, 1, 1, 1, 1])

Upvotes: 1

Related Questions