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 NaN
s by 0
:
Notice: All NaN
s are replaced by 0
, so NaN
s 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"