Facebook Page Twitter Page LinkedIn Page
× Pandas Tutorial Pandas Resources


The Pandas package contains a number of arithmetic functions which provides all the functionality required for various arithmetic operations on a DataFrame. Below mentioned are the most frequently used arithmetic functions.

FunctionDescription
add() Add arguments element-wise.
sub() Subtract arguments, element-wise.

Lets discuss these functions in detail:

Basic Arithmetic Operations

Basic arithmetic operations can be performed on a given DataFrame, element-wise using add(), sub(), mul() and div() functions. The syntax for using this function is given below:

Syntax

DataFrame.add(other, axis='columns', level=None, fill_value=None)
DataFrame.sub(other, axis='columns', level=None, fill_value=None)
DataFrame.mul(other, axis='columns', level=None, fill_value=None)
DataFrame.div(other, axis='columns', level=None, fill_value=None)

Parameters

other Required. Specify any single or multiple element data structure, or list-like object.
axis Optional. Specify whether to compare by the index (0 or 'index') or columns (1 or 'columns'). For Series input, axis to match Series index on. Default is 'columns'.
level Optional. Specify int or label to broadcast across a level, matching Index values on the passed MultiIndex level. Default is None.
fill_value Optional. Specify value to fill existing missing (NaN) values, and any new element needed for successful DataFrame alignment. If data in both corresponding DataFrame locations is missing the result will be missing. Default is None.