Search code examples
pandasdataframerounding

Pandas rounding


I have the following sample dataframe:

Market Value
0  282024800.37
1  317460884.85
2 1260854026.24
3  320556927.27
4   42305412.79

I am trying to round the values in this dataframe to the nearest whole number. Desired output:

Market Value

282024800
317460885
1260854026
320556927
42305413

I tried:

df.values.round()

and the result was

Market Value

282025000.00 
317461000.00 
1260850000.00 
320557000.00 
42305400.00 

What am I doing wrong?

Thanks


Solution

  • This might be more appropriate posted as a comment, but put here for proper format.

    I can't produce your result. With numpy 1.18.1 and Pandas 1.1.0,

    df.round().astype('int')
    

    gives me:

       Market Value
    0     282024800
    1     317460885
    2    1260854026
    3     320556927
    4      42305413
    

    The only thing I can think of is that you may have a 32 bit system, where

    df.astype('float32').round().astype('int')
    

    gives me

       Market Value
    0     282024800
    1     317460896
    2    1260854016
    3     320556928
    4      42305412