Some binary functions such as, add, sub, mul, div, mod, and pow, perform common arithmetic operations involving two DataFrames or series.
The following example shows the addition of two DataFrames. One of the DataFrames has the shape (2,3) while the other has the shape (1,3). The add function performs an elementwise addition. When a corresponding element is missing in any of the DataFrames, the missing values are filled with NaNs:
df_1 = pd.DataFrame([[1,2,3],[4,5,6]])df_2 = pd.DataFrame([[6,7,8]])df_1.add(df_2)
The following is the output:
Instead of using NaNs, ...