Hi I would like to remove all ".0" at the end of a string for an entire DataFrame and I need it to be an exact match.
Let's make an example df:
a b c
20 39.0 17-50
34.0 .016.0 001-6784532
The desired output:
a b c
20 39 17-50
34 .016 001-6784532
I tried using replace
but it didn't work for some reason (I read maybe because replace only replaces entire strings and not substrings?). Either way, if there is a way it can work I'm interested to hear about it because it would work for my dataframe but I feel it's less correct in case I'll have values like .016.0 beacause then it would also replace the first 2 characters.
Then I tried sub and rtrim with regex r'\.0$'
but I didn't get this to work either. I'm not sure if it's because of the regex or because these methods don't work on an entire dataframe. Also using rtrim with .0
didn't work because it removes also zeros without a dot before and then 20 will become 2.
When trying sub and rtrim with regex I got an error that dataframe doesn't have an attribute str
, how is that possible?
Is there anyway to do this without looping over all columns?
Thank you!