Arithmetic Operations 2
Understand the various pandas methods used for performing arithmetic operations.
Arithmetic Operations
Having covered the basic arithmetic operations of addition, subtraction, and multiplication, let's explore the rest of the operations, which are division, modulo, and power.
Note: The details, methods, and examples explained for
add()
in the earlier lesson also apply to thepandas
arithmetic operations here, therefore detailed explanations won’t be repeated in this lesson.
Division—floating point and integer
There are two types of pandas
methods related to the division arithmetic operation, based on whether the operation is a floating point or integer division.
Floating point division: The
div()
ortruediv()
(both methods give the same result)Integer division: The
floordiv()
The floating point division methods correspond to the arithmetic operator /
, while the integer division corresponds to //
. Floating point division is used when the operands are floating point numbers, which results in a floating point number with decimal places. For example, we can perform a floating point division on all the float values in the Iris dataset, shown below:
Get hands-on with 1200+ tech skills courses.