I do realize this has already been addressed here (e.g., Convert list of dictionaries to a pandas DataFrame, Convert nested list of dictionaries to pandas DataFrame, How to transform a list of dictionaries, containing nested lists into a pandas df, Accessing values in a list of nested dictionaries)
Nevertheless, I hope this question was different.
I have a dataframe of inconsistent length with list of nested dictionaries
import pandas as pd
import numpy as np
data = pd.DataFrame({"List_Dict": [[{'PID': '03', 'Col_par': [{'PID': '01', 'mace': [{'all': 100, 'd_Loc': 'front'}]}]}],
np.nan,
[{'PID': '01', 'Col_par': [{'PID': '02', 'mace': [{'all': 100, 'd_Loc': 'driver side'}]}]}],
[{'PID': '02', 'Col_par': [{'PID': '01', 'mace': [{'all': 100, 'd_Loc': 'rear'}, {'all': 100, 'd_Loc': 'passenger side'}, {'all': 100, 'd_Loc': 'front'}]}]}],
[{'PID': '03', 'Col_par': [{'PID': '01', 'mace': [{'all': 30, 'd_Loc': 'front'}]}]}, {'PID': '01', 'Col_par': [{'PID': '03', 'mace': [{'all': 70, 'd_Loc': 'front'}]}]}],
[{'PID': '03', 'Col_par': [{'PID': '01', 'mace': [{'all': 30, 'd_Loc': 'front'}]}]}, {'PID': '01', 'Col_par': [{'PID': '03', 'mace': [{'all': 70, 'd_Loc': 'front'}]}]}],
[{'PID': '02', 'Col_par': [{'PID': '01', 'mace': [{'all': 100, 'd_Loc': 'front'}]}, {'PID': '04', 'mace': [{'all': 100, 'd_Loc': 'front'}]}]}, {'PID': '04', 'Col_par': [{'PID': '01', 'mace': [{'all': 0, 'd_Loc': 'front'}]}]}, {'PID': '01', 'Col_par': [{'PID': '04', 'mace': [{'all': 0, 'd_Loc': 'front'}]}]}],
[{'PID': '01', 'Col_par': [{'PID': '02', 'mace': [{'all': 100, 'd_Loc': 'rear'}, {'all': 100, 'd_Loc': 'front'}]}, {'PID': '03', 'mace': [{'all': 100, 'd_Loc': 'rear'}]}]}, {'PID': '03', 'Col_par': [{'PID': '02', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}]}, {'PID': '02', 'Col_par': [{'PID': '03', 'mace': [{'all': 0, 'd_Loc': 'rear'}]}]}],
[{'PID': '01', 'Col_par': [{'PID': '11', 'mace': [{'all': 0, 'd_Loc': 'front'}]}, {'PID': '14', 'mace': [{'all': 23, 'd_Loc': 'rear'}]}, {'PID': '06', 'mace': [{'all': 0, 'd_Loc': 'rear'}]}]}, {'PID': '06', 'Col_par': [{'PID': '11', 'mace': [{'all': 0, 'd_Loc': 'front'}]}, {'PID': '01', 'mace': [{'all': 0, 'd_Loc': 'front'}]}, {'PID': '14', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}, {'PID': '10', 'mace': [{'all': 0, 'd_Loc': 'rear'}]}]}, {'PID': '14', 'Col_par': [{'PID': '11', 'mace': [{'all': 0, 'd_Loc': 'front'}]}, {'PID': '01', 'mace': [{'all': 0, 'd_Loc': 'front'}]}, {'PID': '06', 'mace': [{'all': 25, 'd_Loc': 'rear'}, {'all': 100, 'd_Loc': 'front'}]}, {'PID': '10', 'mace': [{'all': 100, 'd_Loc': 'rear'}]}]}, {'PID': '11', 'Col_par': [{'PID': '01', 'mace': [{'all': 100, 'd_Loc': 'front'}]}, {'PID': '14', 'mace': [{'all': 53, 'd_Loc': 'rear'}]}, {'PID': '06', 'mace': [{'all': 0, 'd_Loc': 'rear'}]}]}, {'PID': '10', 'Col_par': [{'PID': '14', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}, {'PID': '06', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}]}],
[{'PID': '03', 'Col_par': [{'PID': '01', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}, {'PID': '06', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}, {'PID': '09', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}]}, {'PID': '06', 'Col_par': [{'PID': '01', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}, {'PID': '03', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}, {'PID': '09', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}]}, {'PID': '08', 'Col_par': [{'PID': '01', 'mace': [{'all': 100, 'd_Loc': 'rear'}, {'all': 100, 'd_Loc': 'front'}]}, {'PID': '03', 'mace': [{'all': 100, 'd_Loc': 'rear'}, {'all': 100, 'd_Loc': 'front'}]}, {'PID': '06', 'mace': [{'all': 100, 'd_Loc': 'rear'}, {'all': 100, 'd_Loc': 'front'}]}, {'PID': '09', 'mace': [{'all': 100, 'd_Loc': 'rear'}, {'all': 100, 'd_Loc': 'front'}]}]}, {'PID': '09', 'Col_par': [{'PID': '01', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}, {'PID': '03', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}, {'PID': '06', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}]}, {'PID': '01', 'Col_par': [{'PID': '03', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}, {'PID': '06', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}, {'PID': '09', 'mace': [{'all': 0, 'd_Loc': 'rear'}, {'all': 0, 'd_Loc': 'front'}]}]}]]})
I want to transform the above list of nested dictionaries. I'm open to new ideas and approaches and wanted to put some feelers out before diving into getting started. What is the optimal way of transforming the above data?
Can anybody shed some light on transforming the above data with Python? I would be happy to receive any leads on it from you.