9951 explained code solutions for 126 technologies


python-pandasHow to create pivot table from data frame


import pandas as pd

df = pd.DataFrame({
  'type': ['A', 'A', 'A', 'B', 'B', 'C'],
  'age': [1, 3, 6, 3, 4, 1]
})

pvt = pd.pivot_table(df , index=['type'], aggfunc=['max'])ctrl + c
import pandas as pd

load Pandas module

pd.DataFrame

creates Pandas DataFrame object

pd.pivot_table

creates pivot table from given DataFrame and configuration

index=

defines list of columns to use as pivot indexes (rows)

aggfunc=

defines aggregate functions to use for column values