我有一个数据框(见下文),我想通过它来隔离超过一定数量(60)的值并让它返回月份,我该怎么做:
Month Increase
0 Jan 34
1 Feb 4
2 Mar 33
3 Apr 12
4 May 66
答案 0 :(得分:1)
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
答案 1 :(得分:0)
尝试使用过滤:
df[df['Increase']>60 ]
# Month Increase
#4 May 66
df[df['Increase']>60 ]['Month']
#4 May
#Name: Month, dtype: object