Skip to content

Instantly share code, notes, and snippets.

@lockefox
Last active August 22, 2017 19:34
Embed
What would you like to do?
data_columns = ['killID', 'solarSystemID', 'killTime', 'moonID']
pivot_column = 'items'
index_column = 'killID'
## Make source DataFrame ##
raw_df = pd.DataFrame(raw_data)
## Row-by-row rotate and append desired data ##
result_df = None
for row in raw_df.itertuples():
row_df = pd.DataFrame(getattr(row, pivot_column))
row_df[index_column] = getattr(row, index_column)
result_df = pd.concat([result_df, row_df], axis=0, ignore_index=True)
## Merge source/pivot together ##
result_df = result_df.join(raw_df, index_column, lsuffix='_')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment