Sum of Columns & Rows of pandas DataFrame in Python (Examples) | sum() Function | Each Column & Row

Published: 07 December 2022
on channel: Statistics Globe
758
6

How to calculate the sums of columns and rows of a pandas DataFrame in the Python programming language. More details: https://statisticsglobe.com/sum-of-co...
Python code of this video:

import pandas as pd # Load pandas

data = pd.DataFrame({'x1':[6, 2, 7, 1, 9, 3, 4, 9], # Create example DataFrame
'x2':[2, 5, 7, 1, 3, 1, 2, 3],
'x3':range(8, 0, - 1)})
print(data) # Print example DataFrame

print(data.sum()) # Get column sums
x1 41
x2 24
x3 36
dtype: int64

print(data.sum(axis = 1)) # Get row sums
0 16
1 14
2 20
3 7
4 16
5 7
6 8
7 13
dtype: int64

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – R Programming Group for Discussions & Questions:   / statisticsglobe  
Facebook – Python Programming Group for Discussions & Questions:   / statisticsglobepython  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – R Programming Group for Discussions & Questions:   / 12555223  
LinkedIn – Python Programming Group for Discussions & Questions:   / 12673534  
Twitter:   / joachimschork  

Music by bensound.com


Watch video Sum of Columns & Rows of pandas DataFrame in Python (Examples) | sum() Function | Each Column & Row online, duration hours minute second in high quality that is uploaded to the channel Statistics Globe 07 December 2022. Share the link to the video on social media so that your subscribers and friends will also watch this video. This video clip has been viewed 758 times and liked it 6 visitors.