Skip to content

Instantly share code, notes, and snippets.

@ebergam
Last active February 6, 2018 09:21
Show Gist options
  • Save ebergam/c9757e1f719158d3964d292070466708 to your computer and use it in GitHub Desktop.
Save ebergam/c9757e1f719158d3964d292070466708 to your computer and use it in GitHub Desktop.
Non-numeric pivot tables in Pandas
import pandas as pd
import csv
df = pd.read_csv('data_raw.csv')
df
pivot_table = df.pivot_table(index=['id'],
columns=['key'],
values=['value'],
aggfunc=lambda x: ' '.join(str(v) for v in x))
pivot_table.to_csv('data_pivot.csv')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment