Calculate Sum of DataFrame Columns in Pandas
This Snippet is coded by a user inOnline python Compiler. You can see and run this code too.
زبان: python
This code uses the pandas library to create a DataFrame and calculates the sum of numeric columns (age and salary), printing the results.
To compute the sum of a specific column, use df['column'].sum(). You can also use df.sum() to get the sum of all numeric columns automatically.
- Create DataFrame: Built from a dictionary of data.
- Calculate sum: The
sum()function is applied to the Series. - Output: Prints sum of age (113) and sum of salary (240000).