# copy data between two dataframes in python

I have two different dataframes, both containing a common element (identifier). I want to copy data from df1 for each identifier in df2 (each identifier can repeat maximum 5 times in df1)

df1 ---data vertically

id_column         value1
identifier1       some data1
identifier1       some data2
identifier1       some data3
identifier2       some data2
identifier2       some data1
identifier3       some data3


While df2 looks like this and this is how the information should be copied from df1:

df2 ---data horizontally

id_column        new1          new2           new3

identifier1      some data1      some data2       some data3
identifier2      some data2      some data1
identifier3      some data3


Is there a way to do this with python?

Many thanks for any help

If you want to add the data from df1 to df2 you can use pandas.merge. Given that you want to keep all records from df2 and only add data from df1 for the identifiers in df2 you can use the following syntax:
import pandas as pd

• You can use pandas.melt to convert data from wide to long or pandas.pivot to reshape your data even more freely. – Oxbowerce Jan 28 at 13:58