I would like to join two dataframes (df1,df2), but i can't figure it.
import pandas as pd
data = {'Step_ID': ["Step1", "Step1", "Step1", "Step2", "Step2", "Step3", "Step3"],
'value_01': [2, 2.3, 2.2, 0, 0, 5, 5.2]}
df1 = pd.DataFrame(data)
data = {'Step_ID': ["Step1", "Step1", "Step1", "Step1", "Step2", "Step2", "Step2", "Step3", "Step3", "Step3"],
'value_02': [2.3, 2.5, 2.1, 2.5, 0, 0, 0, 5.1, 5.6, 5.8]}
df2 = pd.DataFrame(data)
I would like to merge the on the column "Step_ID" as follows:
I tried several merges and its settings, but without any sucess.
pd.merge(df1, df2, left_on = ['Step_ID'], right_on = ['Step_ID'], how = 'outer')
The closest solution i have done with the following code, but it is not as required:
df1.combine_first(df2)
Is there any possibility to join those two dataframe in the required way? See the picture above.