How would I go about re-shaping the following data frame so the unique entries in the keys column become new columns, with the values column becoming the row values for each. The data is mixed in each element which I'd planned to change once the data is "flipped" / transposed.
I've tried pivot / pivot_table but I end up with a lot of NaN due to aggregating. I don't want to aggregate I'd like to do something like transpose, but without transposing all the duplicates Key entries to new columns (the JSON File No. entry can be also be dropped if its required as it's not really needed).
The data repeats throughout the file as follows, with the next entry repeating at 'race_id'. It's worth noting for the race_id element, every other key below it (e.g. date, course_id, course etc) is common to it e.g. the race_id in each block is in fact the index for each block of 24 (the 2nd picture below titled "Intended Structure" represents this better)

The columns I'd like are as follows:
'race_id'
'date'
'course_id'
'course'
'off_time'
'race_name'
'distance_round'
'distance'
'distance_f'
'region'
'pattern'
'race_class'
'type'
'age_band'
'prize'
'field_size'
'going_detailed'
'rail_movements'
'stalls'
'weather'
'going'
'surface'
'runners'
The final element 'runners' is actually a nested list which I'd like to explode.
I actually got it to work using the following code, however it only works on the first element, but it should provide a better explanation for what I'm aiming for:
df_3 = pd.pivot_table(df_3, columns='Keys', index='JSON File No.', values='Values', aggfunc='first')
Intended Structure - only applied to one repeated element

Any assistance would be appreciated
