Pandas > Apply function along axis

Name
Code
Output
dataframe = pandas.DataFrame(numpy.random.randint(0,100,size=(5, 2)), columns=['C1','C2'])
print ("dataframe")
print (dataframe)
# sum for columns
sum_columns = dataframe[['C1','C2']].apply(sum,axis=0)
print ("sum for columns")
print (sum_columns)
# sum for rows
sum_rows = dataframe[['C1','C2']].apply(sum,axis=1)
print ("sum for rows")
print (sum_rows)
dataframe
   C1  C2
0  56   2
1  94  89
2   0  56
3  62  80
4  80  98
sum for columns
C1    292
C2    325
dtype: int64
sum for rows
0     58
1    183
2     56
3    142
4    178
dtype: int64