I want to merge two dataframe - Lifetime_df and Input_DataFrame2. The final Lifetime_df should contain everything which it had, but replaced with count of Input_DataFrame2 for matching columns ['Identifier_column', 'lifetime']
Lifetime_df
Identifier_column lifetime count
0 138122 1 1
1 138122 2 1
2 138122 3 NaN
3 138122 4 NaN
4 138122 5 0
5 138122 6 1
6 138122 7 NaN
7 138122 8 0
8 138122 9 1
Input_DataFrame2
Identifier_column lifetime count
0 138122 1 1
1 138122 2 4
2 138122 6 1
3 138122 9 1
Desired Output:
Lifetime_df
Identifier_column lifetime count
0 138122 1 1
1 138122 2 4
2 138122 3 NaN
3 138122 4 NaN
4 138122 5 0
5 138122 6 1
6 138122 7 NaN
7 138122 8 0
8 138122 9 1
The following command's output doesn't satisfy the requirement
Input_DataFrame3 = pd.merge(Lifetime_df,
Input_DataFrame2,
how='left',
on=[Identifier_column, lifetime])
Lifetime_df['count'] = Input_DataFrame3['count_y']
Getting:
Lifetime_df
Identifier_column lifetime count
0 138122 1 1
1 138122 2 4
2 138122 3 NaN
3 138122 4 NaN
4 138122 5 NaN
5 138122 6 1
6 138122 7 NaN
7 138122 8 NaN
8 138122 9 1