DF1:
A B C
0 1 2 6
1 2 3 6
2 3 4 6
3 4 4 6
DF2:
A B C
0 2.0 3.0 7
1 3.0 3.0 7
2 NaN NaN 7
3 NaN NaN 7
4 4.0 4.0 7
Expected:
A B C_x C_y
0 2 3 6 7
3 NaN NaN 6 7
4 NaN NaN 6 7
5 4 4 6 7
I have been trying the below code
code:
import numpy as np
import pandas as pd
def get_df_merged_result(df1, df2, join_condition, column_list):
return pd.merge(df1, df2, how=join_condition , on=column_list)
#Create a DataFrame
df1=pd.DataFrame({'A':[1,2,3,4],'B':[2,3,4,4], 'C':[6,6,6,6]})
df2=pd.DataFrame({'A':[2,3,np.nan,np.nan,4],'B':[3,3,np.nan,np.nan,4],'C':[7,7,7,7,7]})
print(df1)
print('-------------')
print(df2)
print('-------------')
print(get_df_merged_result(df1, df2, 'inner', ['A','B']))
Can somebody help in getting merged result of not null along with null columns.I tried with inner and left join conditions