Posts

Showing posts with the label pivot tables

Aggregation and Groupby Operations

Aggregation and Groupby Operations are important aspects of data analysis with Pandas. Aggregation functions allow us to perform mathematical operations such as sum, mean, median, and others on our data. Groupby operations allow us to group our data based on a specific column and perform operations on each group. Pivot tables allow us to summarize our data and perform calculations on subsets of our data. Aggregation functions: Pandas provides a set of built-in functions for aggregation such as sum, mean, median, min, max, etc. These functions can be applied to Series or DataFrame objects. Example: python Copy code import pandas as pd   df = pd.DataFrame({ 'A' : [ 1 , 2 , 3 , 4 ], 'B' : [ 5 , 6 , 7 , 8 ], 'C' : [ 9 , 10 , 11 , 12 ]}) print (df)  # Sum of all columns   print (df. sum ())  # Mean of all columns   print (df.mean())  # Maximum value of each column   print (df. max ()) Output: less Copy code   A    B    C   0   1    5    9   1 2  6  10   2