I have a dictionary with as values a list of dictionaries and these lists are of variable length. I have tried a lot, but can't get the data properly transformed to a Pandas dataframe.
The data looks like this:
{key1: [{'column5': 40, 'column1': 1, 'column2': 6, 'column3': 170, 'column4': 300}],
key2: [{'column5': 6, 'column1': 33, 'column2': 5, 'column3': 76, 'column4': 13}],
key3: [{'column5': 7, 'column1': 44, 'column2': 2, 'column3': 67, 'column4': 13}, {'column5': 45, 'column1': 400, 'column2': 100, 'column3': 12, 'column4': 145}]}
I want to get a frame like this:
column1 column2 column3 ..
key1 1 6 170
key2 33 5 76
key3 33 2 67
key3 400 100 12
.
.
I either get errors like 'Arrays must all be of same length' when using pd.DataFrame.from_records and when using orient=index, the data is still as a dictionary placed in the dataframe. Some of the things I've tried:
df = pd.DataFrame.from_dict(a, orient='index')
df.transpose() //Data is not properly placed in the dataframe
df = pd.DataFrame.from_records(dataset, orient='index') //Data is not properly placed in the dataframe
df = pd.DataFrame.from_records(dataset) //Gives error about length of arrays
df = pd.DataFrame.from_dict(dataset).T //Gives error about length of arrays
How should I go about this? Thanks a lot!