Python 3.x 如何获取字典中每行的值?

Python 3.x 如何获取字典中每行的值?,python-3.x,pandas,dataframe,Python 3.x,Pandas,Dataframe,我想把每一行的数据放到字典里 S1 S2 S3 S4 Con1 -0.166277 0.329279 5.4941 3.6587 Con2 -0.015557 0.063506 6.5012 -2.6939 Con3 -0.230677 0.525414 7.2712 8.8743 Con4 -0.155739 0.335635 -6.2533 -4.6159 当我使用max_dict=df.to_dic

我想把每一行的数据放到字典里

            S1        S2       S3      S4 
Con1  -0.166277  0.329279  5.4941  3.6587
Con2  -0.015557  0.063506  6.5012 -2.6939
Con3  -0.230677  0.525414  7.2712  8.8743
Con4  -0.155739  0.335635 -6.2533 -4.6159

当我使用max_dict=df.to_dict('dict')时,它如下所示

{
'S1 ': {'Con1': -0.166277, 'Con2': -0.01555, 'Con3': -0.23067, 'Con4': -0.155738}, 
'S2 ': {'Con1': 0.32927, 'Con2': 0.063506, 'Con3': 0.5254, 'Con4': 0.33565}, 
'S3 ': {'Con1': 5.4941, 'Con2': 6.5012, 'Con3': 7.2712, 'Con4': -6.2533}, 
'S4 ': {'Con1': 3.6587, 'Con2': -2.6939, 'Con3': 8.8743, 'Con4': -4.6159}, 
}

预期结果:

{
'Con1': {'S1': -0.166277, 'S2': 0.32927, 'S3': 5.4941, 'S4': 3.6587}, 
'Con2': {'S1': -0.01555,  'S2': 0.063506,'S3': 6.5012, 'S4': -2.6939}, 
'Con3': {'S1': -0.23067,  'S2': 0.5254,  'S3': 7.2712, 'S4': 8.8743}, 
'Con4': {'S1': -0.155738, 'S2': 0.33565, 'S3': -6.2533,'S4': -4.6159}, 
}

df.to_dict(orient='index')