Python Pandas Library pivot_table function

27 June 2023 67 Reading time: 22 second

The pivot_table function in the Pandas library is used to create a summary table on a DataFrame. This function groups the data based on one or more columns and presents the results in tabular form with calculated summary statistics.


import pandas as pd

# Create a pivot table based on 'column1' and 'column2' columns
summary_table = df.pivot_table(values='value', index='column1', columns='column2', aggfunc='mean')
print(summary_table)

Similar articles