Skip to content Skip to sidebar Skip to footer

Python - The Best Way To Create A New Dataframe From Two Other Dataframes With Different Shapes?

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, each row is da

Solution 1:

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)

enter image description here


Post a Comment for "Python - The Best Way To Create A New Dataframe From Two Other Dataframes With Different Shapes?"