logo
  • Home
  • Contact
💵
Should I be buying I-Bonds in 2023?
💰
Need a step-by-step guide to opening your Roth IRA?
Buy me a coffee Buy me a coffee
aws c++ career cli css docker finance git java js misc python sql

How to Divide Column By a Number in Pandas


How can we divide all values in a column by some number in a DataFrame?

Example scenario

Suppose we’re dealing with a DataFrame df that looks something like this.

   A      B
0  11.11  0.22
1  33.33  0.44

We want to divide every number in column A by 100.

   A       B
0  0.1111  0.22
1  0.3333  0.44

Divide column by a number

We can divide by a number using div().

df['A'] = df['A'].div(100)
df['A'] = (df['A'] / 100) # Same output

Related in Python

How to Append to a File or Create If Not Exists in Python
How to Sleep in Python (adding delays)
How to Run `conda activate` in a Shell Script
How to Set Axis Range in Matplotlib (Python)
How to Calculate Mean Across the Row or Column in a NumPy Array
How to Install Playwright with Conda in Python
How to Get Rows or Columns with NaN (null) Values in a Pandas DataFrame
How to Create a Pandas DataFrame
How to Delete a Row Based on a Column Value in a Pandas DataFrame
How to Get the Maximum Value in a Column of a Pandas DataFrame
How to Keep Certain Columns in a Pandas DataFrame
How to Count Number of Rows or Columns in a Pandas DataFrame
How to Add List to Set in Python
How to Fix "Assertion !bs->started failed" in PyBGPStream
How to Add a Row to a Pandas DataFrame
How to Remove Duplicate Columns on Join in a Spark DataFrame
© , LogFetch   âˆ™   Advertise Here   âˆ™   Privacy Policy