Python - function similar to VLOOKUP (Excel)

后端 未结 4 1830
鱼传尺愫
鱼传尺愫 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条回答
  •  Happy的楠姐
    2021-02-05 23:31

    The join method acts very similarly to a VLOOKUP. It joins a column in the first dataframe with the index of the second dataframe so you must set MODEL as the index in the second dataframe and only grab the MAKE column.

    df.join(df1.set_index('MODEL')['MAKE'], on='MODEL')
    

    Take a look at the documentation for join as it actually uses the word VLOOKUP.

提交回复
热议问题