I have the following dictionary (df) of dataframes:
([('Austria',
Name Value
0 3 BG EMCore Convertibles Global CHF R T 5
1 3 BG EMCore Convertibles Global R T 6
[2 rows x 2 columns]),
('Belgium',
Name Value
0 AG Life Alternative Investments 7
1 AG Life Balanced 1
2 AG Life Bonds Global 2
3 AG Life Bonds Indexed 7
[4 rows x 2 columns])])
I want to convert the data into a single dataframe and simultaneously set as additional column the key strings
I first convert the dictionary into a list of dataframes:
mylist=[i[1] for i in df.items()]
Then I can merge the dataframes into a single dataframe by:
master_frame=pd.concat(mylist, sort=True)
But I want to set as additional column the keys from the dictionary
Expected result if like this:
Name Value Country
0 3 BG EMCore Convertibles Global CHF R T 5 Austria
1 3 BG EMCore Convertibles Global R T 6 Austria
2 AG Life Alternative Investments 7 Belgium
3 AG Life Balanced 1 Belgium
4 AG Life Bonds Global 2 Belgium
5 AG Life Bonds Indexed 7 Belgium
Thanks in advance