Jun-30-2024, 10:18 PM
Thanks everyone,
I went with the below because it is the cleanest and most simple:
This is just the beginning of the data cleaning process. I've got lots of more difficult coding issues to share, watch this space ;)
I went with the below because it is the cleanest and most simple:
df2 = pd.DataFrame(df2) # Pivot the DataFrame pivot_df = df2.pivot_table(index=['Date', 'Site Description'], columns='Class Weight', values='Traffic Count', aggfunc='sum', fill_value=0) pivot_df.columns = [f'{col}_class' for col in pivot_df.columns] # Reset index to get Date and id back as columns pivot_df = pivot_df.reset_index() print(pivot_df)The pivot table function is interesting, the index appears to work like a group by. I read the pandas documentation on this function and it does not explain this clearly :(
This is just the beginning of the data cleaning process. I've got lots of more difficult coding issues to share, watch this space ;)