pandas.DataFrame.add() Function with example in python

Spread the love

pandas.DataFrame.add(): This function returns Addition of dataframe and other, element-wise (binary operator add).

Syntax: DataFrame.add(other, axis=’columns’, level=None, fill_value=None)

Equivalent to dataframe + other, but with support to substitute a fill_value for missing data in one of the inputs. With reverse version, radd.

Among flexible wrappers (add, sub, mul, div, mod, pow) to arithmetic operators: +, -, *, /, //, %, **.

other : scalar, sequence, Series, or DataFrame
Any single or multiple element data structure, or list-like object.

axis : {0 or ‘index’, 1 or ‘columns’}
Whether to compare by the index (0 or ‘index’) or columns (1 or ‘columns’). For Series input, axis to match Series index on.

level : int or label
Broadcast across a level, matching Index values on the passed MultiIndex level.

fill_value : float or None, default None
Fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment, with this value before computation. If data in both corresponding DataFrame locations is missing the result will be missing.

Result of the arithmetic operation.

df = pd.DataFrame({'x': [1, 2, 2], 'y': [30, 40, 50]}) print(df.add(1)) print(df.add(10))


   x   y
0  2  31
1  3  41
2  3  51
    x   y
0  11  40
1  12  50
2  12  60




Leave a Reply

Your email address will not be published. Required fields are marked *