I have a dictionary which contains dictionaries which contain dataframes
dict
key value
s0 sub_dict1
s1 sub_dict2
sub_dict1
key value
x1 df1
x2 df2
df1
time val other_data_i_don't_want
0:01 1 999
0:34 2 999
What I ultimately want is a dictionary which contains dataframes as the values
dict_new
key value
s0 df
where df
time val_x1 val_x2 val_x3
0:01 1 1 1
and i want to automate this process in a for loop
so far i have done:
for key1 in dict.keys():
for key2 in dict[key1].keys():
global key1_key2
sensor = str(key2)
key1_key2 = dict[key1][key2][['time','val']]
key1_key2.rename(columns = {"val":'val_'+key2})
but key1_key2 is being defined to have the name "key1_key2" but I actually want to create multiple dataframes named as "s0_x1" "s0_x2" "s1_x1" "s1_x2"
and the rename statement also doesn't work.
once I have the "s0_x1" etc i can do a full outer join to create the df I want. I just can't figure out how to define these as global variables in the first instance