Starting from this previous question: Pandas merge two dataframes with different columns
If I concat two dataframes (A & B) that have some of the same columns, but also have columns that are not present in both, in the resulting dataframe the entries for the columns that are not common to both A & B have a value of NaN. Is there a way to make these entries have another default value?
I would rather not simply replace NaN after the concat operation as there may be NaN values in the original dataframes that I want to preserve.
Here are two example dataframes:
hello world how extra
1 2 3 g
5 -666 11 h
13 NaN i
23 7 29 j
extra you how
1.1 31
b -666 37
c 1.3 41
d NaN 43
-666 1.7 -666
If for example the default value for use in the disjoint columns is "W4L" instead of NaN, the desired result would be:
hello world how extra you
1 2 3 g W4L
5 -666 11 h W4L
13 NaN i W4L
23 7 29 j W4L
W4L W4L 31 1.1
W4L W4L 37 b -666
W4L W4L 41 c 1.3
W4L W4L 43 d NaN
W4L W4L -666 -666 1.7