Skip to content

Instantly share code, notes, and snippets.

@lockefox
Last active August 22, 2017 19:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lockefox/2e6f543216cd7133caf6890faf48aa23 to your computer and use it in GitHub Desktop.
Save lockefox/2e6f543216cd7133caf6890faf48aa23 to your computer and use it in GitHub Desktop.
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