Python - the best way to create a new dataframe from two other dataframes with different shapes?

前端 未结 1 997
不知归路
不知归路 2021-01-28 14:06

Essentially, I\'m trying to build a new dataframe from two others but the situation is a little complicated and I\'m not sure what the best way to do this is.

In DF1, e

1条回答
  •  梦毁少年i
    2021-01-28 14:26

    Check if below lines can help you to add columns from DF1 to new frame, I have taken frame through excel you can use your own way...data used is displayed in image

    import pandas as pd
    df1 = pd.read_excel('frame1.xlsx')
    df2 = pd.read_excel('frame2.xlsx')
    
    df = pd.merge(df2, df1[['ID','datafield1','datafield2']], on = 'ID', how = 'left')
    
    print(df)
    

    0 讨论(0)
提交回复
热议问题