需求:当我们处理一行数据时,要求这一行中不同列的最值、最大值、最小值、均值等数据。
如例:
name | Chinese | Math | English | PE |
tom | 88 | 87 | 89 | 90 |
tony | 98 | 97 | 99 | 90 |
leo | 67 | 78 | 89 | 91 |
bob | 90 | 89 | 91 | 97 |
统计每位学生的成绩最大值,最小值,平均值。
以最大值为例:
#定义获取各科成绩最大值的函数
def getMax(row):
return max(row["Chinese"],row["Math"],row["English"],row["PE"])
df["max"]=(lambda row:getMax(row),axis=1)
其他类似,