I have a dataframe like this:
aa phel ri_s
no
1 a 21 76
2 s 32 87
3 d 43 98
4 f 54 25
5 g 65 37
and I would like to create a dictionary that looks like this:
{1: {aa: a, phel: 21, ri_s: 76}, 2: {aa: s, phel: 32, ri_s:87}...}
but instead, I am getting this:
{'a': {(0, 'a'): {'phel': 21, 'ri_s': 76}}, 'd': {(2, 'd'): {'phel': 43, 'ri_s': 98}}, 'f': {(3, 'f'): {'phel': 54, 'ri_s': 25}}, 'g': {(4, 'g'): {'phel': 65, 'ri_s': 37}}, 's': {(1, 's'): {'phel': 32, 'ri_s': 87}}}
my current code is:
tsv_in = tsv_in.groupby('aa')['aa','phel', 'ri_s'].apply(
lambda x: x.set_index('aa', 'phel', 'ri_s').to_dict(orient='index')).to_dict()
Any suggestions?
df.to_dict("index")?