How can I apply pandas.pivot_table to the dataframe:
df = pd.DataFrame(
[
{'o1_pkid': 645, 'o2_pkid': 897, 'colname': 'col1', 'colvalue': 'sfjdka'},
{'o1_pkid': 645, 'o2_pkid': 897, 'colname': 'col2', 'colvalue': 25},
{'o1_pkid': 645, 'o2_pkid': 159, 'colname': 'col1', 'colvalue': 'laksjd'},
{'o1_pkid': 645, 'o2_pkid': 159, 'colname': 'col2', 'colvalue': 26}
]
)
to get a multi-indexed result (indexed by o1_pkid and o2_pkid), where the columns come from colname and the values come from colvalue? I am looking to get a result something like:
colname col1 col2
o1_pkid o2_pkid
645 897 'sfjdka' 25
159 'laksjd' 26