sum of a column in pandas
Total = df['MyColumn'].sum()
print (Total)
319
sum of a column in pandas
Total = df['MyColumn'].sum()
print (Total)
319
pandas ttable with sum totals
import numpy as np
import pandas as pd
df = pd.DataFrame({'a': [10,20],'b':[100,200],'c': ['a','b']})
df.loc['Column_Total']= df.sum(numeric_only=True, axis=0)
df.loc[:,'Row_Total'] = df.sum(numeric_only=True, axis=1)
print(df)
a b c Row_Total
0 10.0 100.0 a 110.0
1 20.0 200.0 b 220.0
Column_Total 30.0 300.0 NaN 330.0
python column = sum of list of columns
list_of_my_columns = ['Col A', 'Col E', 'Col Z']
df['Sum'] = df[list_of_my_columns].sum(axis=1)
pandas sum
import pandas as pd
data = {'Month': ['Jan ','Feb ','Mar ','Apr ','May ','Jun '],
'Bill Commission': [1500,2200,3500,1800,3000,2800],
'Maria Commission': [3200,4100,2500,3000,4700,3400],
'Jack Commission': [1700,3100,3300,2700,2400,3100]
}
df = pd.DataFrame(data,columns=['Month','Bill Commission','Maria Commission','Jack Commission'])
print (df)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us