0

I have a number '24.45-' and wanted to move the minus sign from right to left like '-24.45' in Python.I am dealing with huge data in data frame and trying to do this using regex so that I can apply on the whole column. Tried this but with no luck, any suggestions please.

print(re.sub(r"([0-9.]+)((\W$))","\2\1","24.45-"))
martineau
  • 119,623
  • 25
  • 170
  • 301
subzero355
  • 87
  • 1
  • 8

1 Answers1

1

You can always do something like this:

>>> n = '24.45-'
>>> n = n[-1] + n[:-1]
>>> n
'-24.45'
>>> 
dcg
  • 4,187
  • 1
  • 18
  • 32