web123456

pandas finds the maximum value and average value of multiple rows in a column, etc.

Requirements: When we process a row of data, we require data such as the maximum, maximum, minimum, average, etc. of different columns in this row.

As an example:

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

 

Statistics the maximum, minimum and average scores of each student.

Take the maximum value as an example:

#Define the function to obtain the maximum score of each subject
 def getMax(row):
     return max(row["Chinese"],row["Math"],row["English"],row["PE"])


 df["max"]=(lambda row:getMax(row),axis=1)

Others similar,