gpt4 book ai didi

python - Pandas Dataframe - 隔离值

转载 作者:太空宇宙 更新时间:2023-11-03 16:29:40 25 4
gpt4 key购买 nike

我有一个数据框(见下文),我想运行它来隔离高于特定数字(60)的值并让它返回月份,我该怎么做:

   Month   Increase

0 Jan 34
1 Feb 4
2 Mar 33
3 Apr 12
4 May 66

最佳答案

IIUC您可以使用boolean indexing :

mask = df.Increase  > 60
print (mask)
0 False
1 False
2 False
3 False
4 True
Name: Increase, dtype: bool

print (df[mask])
Month Increase
4 May 66

print (df.loc[mask, 'Month'])
4 May
Name: Month, dtype: object

关于python - Pandas Dataframe - 隔离值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37708201/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com