Context: I'd like to create a dictionary with "Variable:values" pairs. The variable has a multindex like this:
Sexo
Masculino Feminino
0 4245.0 4620.0
1 4274.0 4655.0
2 4304.5 4689.5
3 4322.0 4708.5
4 4318.0 4717.5
5 4288.0 4710.5
6 4247.5 4683.5
7 4224.5 4650.5
8 4223.5 4613.5
9 4191.0 4567.0
10 4133.7 4546.9
11 4093.6 4550.1
12 4079.0 4551.5
13 4070.5 4562.6
And I'm creating the dictionary using a dict comprehension:
dict_boxplot = {col:val for (col,val) in zip(subcolumns,df_var.iloc[:,1])}
Where subcolumns
are simply the names "Masculino" and "Feminino". How cold I make a dictionary with this format : {'Masculino': [value1,value2,value3...], 'Feminino': [value1,value2,value3...]} where value1
, etc are the values from each column?
Thank you in advance!
Simply use
to_dict('list')
:Output: