Skip to content

Latest commit

 

History

History
20 lines (13 loc) · 574 Bytes

creating_pivot_table.md

File metadata and controls

20 lines (13 loc) · 574 Bytes

Creating a pivot table

pandas.DataFrame.pivot_table

import pandas as pd

# import data set from csv

df = pd.read_csv('<some file>')

# select the cols you wish to use for the model
df = df [['col1', 'col2', 'col3']]

# create a pivot table from those cols
pivot = df.pivot_table(index='col1', columns='col2', values='col3', aggfunc='sum')

# export to excel
pivot.to_excel('<some file>', sheet_name='sheet1', startrow=4)