Homepage Forums Dev & Debugging How do I remove the decimals from the dataframe?

  • How do I remove the decimals from the dataframe?

     Eric Reek updated 7 months ago 2 Members · 3 Posts
  • Eric Reek

    Member
    December 22, 2020 at 9:28 pm
    489 Coins
    36 Gems
    Level: Rookie

    Hi there, I am new to pandas and need to know how can I remove decimals to integers in dataframe.

    50.00 -> 50
  • Ryan Brook

    Member
    December 22, 2020 at 9:33 pm
    13 Coins
    0 Gems
    Level: Rookie
    Helpful
    Up
    2
    Down
    Not Helpful

    Great question. Many face this conundrum, and there are actually a couple of ways to achieve this:

    1. Convert everything to integers – df.astype(int)
    2. Rounding up – df.round()
    3. Change your display precision option in Pandas – pd.set_option(‘precision’, 0)

    Depending on the type of data you are working with, you can choose which one works best for you.

  • Eric Reek

    Member
    December 24, 2020 at 10:45 pm
    489 Coins
    36 Gems
    Level: Rookie
    Helpful
    Up
    0
    Down
    Not Helpful

    @gaetano85 the data I have is of miles. I think rounding will make it completely redundant. Would you say that converting to integers will be the best option?

Log in to reply.

Original Post
0 of 0 posts June 2018
Now

New Report

Close