I'm rounding a column from my dataframe to the nearest 5 floating point. After that I'm converting the column values into string, but when I do that the float go back as if they were unrounded. I'm using Python 2.7
import pandas as pd
df=pd.read_excel(C:"path")
def custom_round(x, base=5):
return base * round(float(x)/base)
df['A'] = df['kl'].apply(lambda x: custom_round(x, base=.05))
df['b'] = "D = " + df['A'].astype(str)
kl A b
0.600001 0.60 D = 0.6000000000000001
0.600001 0.60 D = 0.6000000000000001
0.600000 0.60 D = 0.6000000000000001
0.600000 0.60 D = 0.6000000000000001
0.600587 0.60 D = 0.6000000000000001
0.601573 0.60 D = 0.6000000000000001
0.601168 0.60 D = 0.6000000000000001
0.600001 0.60 D = 0.6000000000000001
0.600001 0.60 D = 0.6000000000000001
0.600001 0.60 D = 0.6000000000000001
0.600000 0.60 D = 0.6000000000000001
0.600001 0.60 D = 0.6000000000000001
0.600001 0.60 D = 0.6000000000000001
0.600001 0.60 D = 0.6000000000000001
0.600001 0.60 D = 0.6000000000000001
0.850001 0.85 D = 0.8500000000000001