Joining Multiple Dataframes with Pandas with overlapping Column Names?

后端 未结 2 902
囚心锁ツ
囚心锁ツ 2020-12-16 00:27

I have multiple (more than 2) dataframes I would like to merge. They all share the same value column:

In [431]: [x.head() for x in data]
Out[431]: 
[                 


        
2条回答
  •  时光取名叫无心
    2020-12-16 01:22

    I would try pandas.merge using the suffixes= option.

    import pandas as pd
    import datetime as dt
    
    df_1 = pd.DataFrame({'x' : [dt.datetime(2012,10,21) + dt.timedelta(n) for n in range(10)], 'y' : range(10)})
    df_2 = pd.DataFrame({'x' : [dt.datetime(2012,10,21) + dt.timedelta(n) for n in range(10)], 'y' : range(10)})
    df = pd.merge(df_1, df_2, on='x', suffixes=['_1', '_2'])
    

    I am interested to see if the experts have a more algorithmic approach to merge a list of data frames.

提交回复
热议问题