What is the most elegant way to add two pandas DataFrames without getting NaNs in case of one missing column/row.
It is probably better described with this simple example:
index1 = pd.Index(["a", "b"])
data1 = np.full(shape=(2, 2), fill_value=1.0)
df1 = pd.DataFrame(data1, index=index1, columns=index1)
# df1 =
# a b
# a 1.0 1.0
# b 1.0 1.0
index2 = pd.Index(["b", "c"])
data2 = np.full(shape=(2, 2), fill_value=2.0)
df2 = pd.DataFrame(data2, index=index2, columns=index2)
# df2 =
# b c
# b 2.0 2.0
# c 2.0 2.0
df = df1 + df2
The resulting dataframe is
a b c
a nan nan nan
b nan 3.0 nan
c nan nan nan
However, I would like it to be
a b c
a 1.0 1.0 nan
b 1.0 3.0 2.0
c nan 2.0 2.0