【问题标题】:How to take one part of a Series in Pandas?如何参加 Pandas 系列的一部分?
【发布时间】:2021-01-08 18:59:25
【问题描述】:

我如何只取右边的值?前任。只有一个数组/列表 [120, 108, 82...]

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

【问题讨论】:

  • list(d)?此外,您可以使用to_list() 链接您的代码。

标签: python arrays pandas series


【解决方案1】:

您可以简单地使用tolist()valuesto_numpy 方法。这是一个玩具示例:

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

【讨论】:

    猜你喜欢
    • 2021-12-16
    • 2020-10-26
    • 1970-01-01
    • 2021-09-03
    • 2018-02-03
    • 1970-01-01
    • 2019-12-27
    • 1970-01-01
    • 2020-03-04
    相关资源
    最近更新 更多