I am currently working with dictionary D that looks like this:
D = {
'Instagram': [{'total_post': 3}],
'Twitter': [{'total_post': 9}],
'Facebook': [{'total_post': 1}],
'YouTube': [{'total_post': 5}]
}
I want to make a DataFrame with this structure:
total_post
Instagram 3
Twitter 9
Facebook 1
YouTube 5
I think I need to take the key (Instagram, Twitter, Facebook, YouTube, total_post) to make the desired DataFrame, but currently I am having problem finding how to do it. This is my current code, that returns final_df:
list_dataframe = [] #populate dictionary values to a list
for key, values in D.items():
df = pd.DataFrame(values)
list_dataframe.append(df)
# combine dataframe
indexed_df = [df.set_index(index) for df in list_dataframe] #my current index = total_post
final_df = pd.concat(indexed_df, axis=1)
final_df.fillna(0, inplace=True)
This is the list_dataframe current result:
[ total_post
0 3, total_post
0 9, total_post
0 1, total_post
0 5]
What can I do to take keys? Or, is there any better way to process the dictionary D?