Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python calculated row in dataframe subtract

# Dataframe:
# Class     math score   reading score   writing score           
# Class 1      65                73           74
# Class 2      69                66           64

df.loc['Difference'] = df.apply(lambda x: x["Class 1"] - x["Class 2"])

# Result:
# Class       math score    reading score   writing score         
# Class 1         65               73            74
# Class 2         69               66            64
# Difference      -3                7            10
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #calculated #row #dataframe #subtract
ADD COMMENT
Topic
Name
3+8 =