Pandas merge two dataframes with different columns

前端 未结 2 1240
我寻月下人不归
我寻月下人不归 2020-12-02 10:32

I\'m surely missing something simple here. Trying to merge two dataframes in pandas that have mostly the same column names, but the right dataframe has some columns that the

2条回答
  •  青春惊慌失措
    2020-12-02 11:00

    I had this problem today using any of concat, append or merge, and I got around it by adding a helper column sequentially numbered and then doing an outer join

    helper=1
    for i in df1.index:
        df1.loc[i,'helper']=helper
        helper=helper+1
    for i in df2.index:
        df2.loc[i,'helper']=helper
        helper=helper+1
    df1.merge(df2,on='helper',how='outer')
    

提交回复
热议问题