python calculated row in dataframe subtract

Solutions on MaxInterview for python calculated row in dataframe subtract by the best coders in the world

showing results for - "python calculated row in dataframe subtract"
Rafael
26 Nov 2020
1# Dataframe:
2# Class     math score   reading score   writing score           
3# Class 1      65                73           74
4# Class 2      69                66           64
5
6df.loc['Difference'] = df.apply(lambda x: x["Class 1"] - x["Class 2"])
7
8# Result:
9# Class       math score    reading score   writing score         
10# Class 1         65               73            74
11# Class 2         69               66            64
12# Difference      -3                7            10