How to get a row at last of dataframe which is column aggregations. But, it is sum for few and max for other?
import pandas as pd
data = [
["id_1",6,7,9],
["id_2",9,7,1],
["id_3",6,7,10],
["id_4",9,5,10]
]
df = pd.DataFrame(data, columns = ['Student Id', 'Math', 'Physical', 'Flag'])
Student Id Math Physical Flag
0 id_1 6 7 9
1 id_2 9 7 1
2 id_3 6 7 10
3 id_4 9 5 10
I want to get a row at last as total which gives me column sum for Math & Physical and max for Flag. Excluding student_id column
Student Id Math Physical Chemistry
0 id_1 6 7 9
1 id_2 9 7 1
2 id_3 6 7 10
3 id_4 9 5 10
(Total) 30 26 10
I can do the sum of all by below but how to get different aggregations for different columns and also exclude NAN?
df.loc['(TOTAL)'] = df[['Math', 'Physical' ]].sum(axis = 0)