Pandas Series - Broadcasting Operations

By Hemanta Sundaray on 2021-08-14

We can apply an operation to every value in a pandas Series using a feature called broadcasting.

Let’s read the budget.xlsx file into a DataFrame:

import pandas as pd

data = pd.read_excel("budget.xlsx")

data

Output:

Budget

For example, if we wanted to divide every value in the Revenue column with 100000, we can do so using the /= operator.

data["Revenue"] /= 100000

data

Output:

Revenue

Similarly, we can add, subtract and multiply using the +=, -= & *= operators respectively.

Join the Newsletter