Skip to content Skip to sidebar Skip to footer

On The Default/fill Value For Outer Joins

Below are teeny/toy versions of much larger/complex dataframes I'm working with: >>> A key u v w x 0 a 0.757954 0.258917 0.404934 0

Solution 1:

You can fill zeros after the merge:

res = pd.merge(A, B, how="outer")
res.loc[~res.key.isin(A.key), A.columns] = 0

EDIT

to skip key column:

res.loc[~res.key.isin(A.key), A.columns.drop("key")] = 0

Post a Comment for "On The Default/fill Value For Outer Joins"