I'm trying to use an excel file to do something which was put together in a rather annoying format (I did not create it; it's an existing resource I'm using). The values of interest are in a column called (something like) All_Values separated by periods, while the measures corresponding to those values are specified in a separate column, All_Measures, also separated by periods and different for each row. For example, using a toy dataset:
Object All_Measures All_Values (additional columns that are not like this)
1 Height.Weight 20.50 ...
2 Weight.Height 65.30 ...
3 Height.Width.Depth 22.30.10 ...
What I want to do is reformat the data like this, filling in the missing values with 0s (the final order of the columns isn't important):
Object Height Weight Width Depth (additional columns)
1 20 50 0 0 ...
2 30 65 0 0 ...
3 22 0 30 10 ...
One way I can do this is to (very slowly, as it's a large dataset) create a new blank dataframe, and then iterate over each row in the existing one, create a new dataframe row with the columns specified by splitting All_Measures by ., and the values specified by splitting All_Values by .. Then, I remove All_Measures and All_Values from the row and append the new dataframe to the end of it, and append that to the blank dataframe. But this is pretty clumsy and it'd be nice if there were a faster and more elegant way to do it.
Since there's no error here, I don't have a MWE, but here's some code one could copy to create a toy dataset like the above in case it comes in handy.
df = pd.DataFrame(
columns = ['Object','All_Measures','All_Values','Object_Name']
[[1,'Height.Weight','20.50','First'],
[2,'Weight.Height','65.30','Second'],
[3,'Height.Width.Depth','22.30.10','Third']]
)