Last active
December 5, 2025 16:47
-
-
Save ncalm/33224e76cb868247991d0eab74d7ba44 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # https://owenprice.pyscriptapps.com/excel-challenginator/latest/ | |
| import pandas as pd | |
| df['Date'] = pd.to_datetime(df.Data, errors='coerce').ffill() | |
| display(df.head(3), 'After creating Date column (first 3 rows)') | |
| df = df.loc[df.Data!=df.Date] | |
| display(df.head(3), 'After removing date-only rows (first 3 rows)') | |
| df = pd.concat([ | |
| df.Date, | |
| df.Data.str.extract(r'\s([A-C]).+m([0-9]).+\s([0-9]+)') | |
| ], axis=1) | |
| df.columns = ['Date', 'Groups', 'Items', 'Amount'] | |
| df = df.sort_values(by=['Date','Groups']) | |
| display(df.head(3), 'After splitting to columns (first 3 rows)') | |
| f = lambda s: ', '.join(s) | |
| df = df.groupby('Date').agg({ | |
| "Groups":f, | |
| "Items":f, | |
| "Amount":lambda s: s.astype(int).sum()} | |
| ).reset_index() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment