Pandas Merge - How to avoid duplicating columns

前端 未结 5 1421
轮回少年
轮回少年 2020-11-28 02:23

I am attempting a merge between two data frames. Each data frame has two index levels (date, cusip). In the columns, some columns match between the two (currency, adj date

5条回答
  •  离开以前
    2020-11-28 02:43

    I use the suffixes option in .merge():

    dfNew = df.merge(df2, left_index=True, right_index=True,
                     how='outer', suffixes=('', '_y'))
    dfNew.drop(dfNew.filter(regex='_y$').columns.tolist(),axis=1, inplace=True)
    

    Thanks @ijoseph

提交回复
热议问题