0

i want to round the number showing in my table

it looks now like:

enter image description here

i want it looks like:

enter image description here

How can i get that? use pandas or numpy and as simple as possible. Thanks!

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
  • 1
    Welcome to SO, please read [this guide](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) and [this guide](https://stackoverflow.com/help/minimal-reproducible-example) and edit your question accordingly. – Quang Hoang Dec 14 '21 at 16:33

1 Answers1

0

In pandas , we can use pandas.DataFrame.round. See example below ( from pandas documentation )

data frame : df

    dogs  cats
0  0.21  0.32
1  0.01  0.67
2  0.66  0.03
3  0.21  0.18

Do round on df like below

df.round(1)

Output:

    dogs  cats
0   0.2   0.3
1   0.0   0.7
2   0.7   0.0
3   0.2   0.2

We can even specify the fields need to round, see link for more details : pandas.DataFrame.round

Or We can use default python round in a loop, as below

>>> round(5.76543, 2)
5.77
Jithin Scaria
  • 1,271
  • 1
  • 15
  • 26