Python - function similar to VLOOKUP (Excel)

后端 未结 4 1787
鱼传尺愫
鱼传尺愫 2021-02-05 23:00

i am trying to join two data frames but cannot get my head around the possibilities Python has to offer.

First dataframe:

ID MODEL   REQUESTS ORDERS
1  G         


        
4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 23:36

    Although not in this case, but there might be scenarios where df2 has more than two columns and you would just want to add one out of those to df1 based on a specific column as key. Here is a generic code that you may find useful.

    df = pd.merge(df1, df2[['MODEL', 'MAKE']], on = 'MODEL', how = 'left')
    

提交回复
热议问题