I scrape an stock price from an website and the output ist e.g. "12 EUR". How can i remove the EUR from the string inpython , so that i can work with just the number?
Thanks a lot!
I scrape an stock price from an website and the output ist e.g. "12 EUR". How can i remove the EUR from the string inpython , so that i can work with just the number?
Thanks a lot!
Use regex to remove anything that is not a number.
import re
stock = '12 EUR'
stock = re.sub('[^0-9]', '', stock)
The following does not throw an exception when " EUR" is missing:
txt = '123 EUR'
txt = txt.strip(' EUR')
print(txt)
Building on mismaahs answer, a general purpose solution that handles currencies and decimals is:
import re
stock = '1,234.56 EUR'
stock = re.sub('^0-9\.', '', stock)