作者:啊健oo | 来源:互联网 | 2022-12-06 10:50
1> jezrael..:
使用:
s = df.iloc[:, 2:].ge(80).mean().mul(100)
print (s)
history 50.0
english 75.0
math 50.0
biology 50.0
dtype: float64
说明:
首先按位置选择必要的列DataFrame.iloc
:
print (df.iloc[:, 2:])
history english math biology
0 75 90 85 60
1 85 80 95 70
2 55 60 78 86
3 90 89 76 80
然后通过DataFrame.ge
(>=
)进行比较:
print (df.iloc[:, 2:].ge(80))
history english math biology
0 False True True False
1 True True True False
2 False False False True
3 True True False True
通过以下方式得到mean
多个:100
DataFrame.mul
print (df.iloc[:, 2:].ge(80).mean().mul(100))
history 50.0
english 75.0
math 50.0
biology 50.0
dtype: float64