Add Default Values While Merging Tables In Pandas
I'm reading two csv files with pandas. df1= pd.read_csv('file_1.csv') df2 = pd.read_csv('file_2.csv') data = pd.merge(df1, df2, on='id') The problem I'm facing is that the final
Solution 1:
You can use outer join and replace NaNs by 0:
Notice: All NaNs are replaced by 0, so NaNs in df1 or df2 are replaced too.
data = pd.merge(df1, df2, on='id',how='outer').fillna(0)
Post a Comment for "Add Default Values While Merging Tables In Pandas"