0

I would like to check how may we use the simple basic round() function to round values in a pandas dataframe to a specific number of decimal points. I kept playing around but I couldn't get it right and I am very new to Python so am not looking for anything too sophisticated.

I understand if you use round(3.986, 2) it will simply output to 2 d.p. as 3.99.

And I know we may access the df values through df.values.

I tried exploring the df.applymap() function too.

Help !

funkymickey
  • 111
  • 3
  • 8
  • I think you have the right understanding of `round`. What is it that you exactly want to know? – Mayank Porwal Nov 08 '20 at 15:00
  • I would like to know how may we use the round() function to round the values in any given dataframe (df). I know I can access the values via df.values but I can't do round(df.values, 3). – funkymickey Nov 08 '20 at 15:02
  • 1
    [https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.round.html?](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.round.html?) – wwii Nov 08 '20 at 15:03

1 Answers1

1

You can use apply on the column which you want to round the numbers

>>> df['Numeric Column'].apply(lambda x : math.round(x,2))

This will give you the intended result

Vaebhav
  • 4,672
  • 1
  • 13
  • 33