Jason Ching Yuk Jason Ching Yuk - 1 year ago 123
Python Question

Rounding up decimals Python

I am new to python pandas and I am having difficulties trying to round up all the values in the column as there is a white space between the decimal point and zero. For example,

21. 0
8. 0
52. 0
45. 0

I tried using my current code below, but it gave me:

invalid literal for float(): 21. 0


Answer Source

Try using replace on the string to replace all whitespace in the string before converting to a float:

df.Hi.str.replace(' ', '').astype(float).round()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download