Pandas Dataframe Multiindex Merge

前端 未结 4 427
萌比男神i
萌比男神i 2020-12-16 14:31

I wanted to ask a questions regarding merging multiindex dataframe in pandas, here is a hypothetical scenario:

arrays = [[\'bar\', \'bar\', \'baz\', \'baz\'         


        
4条回答
  •  情歌与酒
    2020-12-16 15:09

    Seems like you need to use a combination of them.

    s1.merge(s2, left_index=True, right_on=['third', 'fourth'])
    #s1.merge(s2, right_index=True, left_on=['first', 'second'])
    

    Output:

                   s1        s2
    bar one  0.765385 -0.365508
        two  1.462860  0.751862
    baz one  0.304163  0.761663
        two -0.816658 -1.810634
    foo one  1.891434  1.450081
        two  0.571294  1.116862
    qux one  1.056516 -0.052927
        two -0.574916 -1.197596
    

提交回复
热议问题