How can a pandas merge preserve order?

前端 未结 5 2280
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 03:46

I have two DataFrames in pandas, trying to merge them. But pandas keeps changing the order. I\'ve tried setting indexes, resetting them, no matter what I do, I can\'t get th

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-15 04:14

    I might have a much more simple solution:

    df_z = df_x.join(df_y.set_index('state'), on = 'state')
    

    Hope it helps

提交回复
热议问题