I have the following data that I want convert into pandas dataframe Input
my_dict = {'table_1': [{'columns_1': 148989, 'columns_2': 437643}], 'table_2': [{'columns_1': 3344343, 'columns_2': 9897833}]}
Expected Output
table_name columns_1 columns_2
table_1 148989 437643
table_2 3344343 9897833
I tried below way but due to the loop, i can only get the last value
def convert_to_df():
for key, value in my_dict.items():
df = pd.DataFrame.from_dict(value, orient='columns')
df['table_name'] = key
return df
What I'm I missing?
dfon each iteration of the loop. In any case, the loop is not necessary, as shown in the answer already posted.