I have below string;
line='P1: 6.0, P2: 5.0, P3: 10.3, P4: 7.0, P5: 10.0, P6: 6.0, P7: 4.0, P8: 5.8, P9: 5.0, P10: 5.0'
I only want to delete .0's and keep the values like 4.5 or 10.3. So what I want is like,
line='P1: 6, P2: 5, P3: 10.3, P4: 7, P5: 10, P6: 6, P7: 4., P8: 5.8, P9: 5, P10: 5'
I tried to do this,
import re
re.sub(r'.0(?=,)','',line)
It didn't work. I would appreciate any help.
re.sub(r'(?<=\d)\.0(?![^,])','',line)to make sure you only remove.0after a digit and before a comma/end of string.