• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / Python / pandas floor – Find the Floor of a Column Using Numpy floor

pandas floor – Find the Floor of a Column Using Numpy floor

December 20, 2021 Leave a Comment

To find the floor of numbers in a column using pandas, the easiest way is to use the numpy floor() function.

df["Column"] = df["Column"].apply(np.floor)

Finding the floor of numbers in a column in pandas is easy. We can round down numbers in a column to the nearest integer with the numpy floor() function.

Let’s say we have the following dataframe.

df = pd.DataFrame({'Name': ['Jim', 'Sally', 'Bob', 'Sue', 'Jill', 'Larry'],
                   'Weight': [160.20, 123.81, 209.45, 150.35, 102.43, 187.52]})

print(df)
# Output: 
    Name  Weight
0    Jim  160.20
1  Sally  123.81
2    Bob  209.45
3    Sue  150.35
4   Jill  102.43
5  Larry  187.52

To get the floor of the column “weight”, we can apply the numpy floor() function in the following way:

df["Floor of Weight"] = df["Weight"].apply(np.floor)

print(df)

# Output:
    Name  Weight  Floor of Weight
0    Jim  160.20            160.0
1  Sally  123.81            123.0
2    Bob  209.45            209.0
3    Sue  150.35            150.0
4   Jill  102.43            102.0
5  Larry  187.52            187.0

If you are looking to find the floor of a number in regular Python, you can use the Math.floor() function.

If you want to round up a column to the nearest integer, instead of rounding down, you can use the numpy ceil() function.

Hopefully this article has been helpful for you to use the numpy floor() function to find the floor of numbers in a column using pandas in python.

Other Articles You'll Also Like:

  • 1.  Find Maximum of Three Numbers in Python
  • 2.  What Curly Brackets Used for in Python
  • 3.  Pandas Crosstab on Multiple Columns
  • 4.  Using Python Selenium Webdriver to Refresh Page
  • 5.  Python Destroy Object – How to Delete Objects with del Keyword
  • 6.  How to Check if Number is Divisible by 3 in Python
  • 7.  How to Add Two Numbers in Python
  • 8.  Using pandas to_csv() Function to Append to Existing CSV File
  • 9.  How to Check If File is Empty with Python
  • 10.  Find Quotient and Remainder After Division in Python

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy