Mukul Mukul - 2 months ago 5
Python Question

how to change default precision in python

i have a dataframe with floating type variables, i need to change the values of that variable to a n decimal places. (dummy data)

prod_code sales_avg
122 12332.234233
123 12212.234123

Currently i am doing the following :


i am getting the decimal places upto 6 places(i think that is default). I need to increase the decimal place to 9.but the above code does not work. Later i will be using this variable for comparison, so not looking for just "display" standpoint. The value should be stored as 9 decimal places. What am i doing wrong here.


You can do it as follows:

via Dataframe using Dataframe.round

prod_sales_avg.round({'sales_avg': 9})

via Series using Series.round

prod_sales_avg['sales_avg'] = prod_sales_avg['sales_avg'].round(decimals=9)