I have a main df:
print(df)
item dt_op
0 product_1 2019-01-08
1 product_2 2019-02-08
2 product_1 2019-01-08
...
and a subset of the first one, that contains only one product and two extra columns:
print(df_1)
item dt_op DQN_Pred DQN_Inv
0 product_1 2019-01-08 6 7.0
2 product_1 2019-01-08 2 2.0
...
That I am iteratively creating, with a for loop (hence, df_1 = df.loc[df.item == i] for i in items
).
I would like to merge df_1
and df
, at every step of the iteration, hence updating df with the two extra columns.
print(final_df)
item dt_op DQN_Pred DQN_Inv
0 product_1 2019-01-08 6 7.0
1 product_2 2019-02-08 nan nan
2 product_1 2019-01-08 2 2.0
...
and update the nan at the second step of the for loop, in which df_1
only contains product_2
.
How can I do it?