Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import re
number = r'\d+(,\d{3})*\.*\d*' #$790,000
amount = r'thousand|million|billion' #$12.2 million example
word_re = rf'\${number}(-|\sto\s|–)?(\$*{number})\s?({amount})'
value_re = rf'\${number}'
def parse_word_syntax(string):
value_string =,string).group()
value = float(value_string.replace(',',''))
word =,string,flags=re.I).group().lower()
word_value = word_to_value(word)
return value * word_value
def word_to_value(word):
value_dict ={'thousand':1000,'million':1000000,'billion':1000000000}
return value_dict[word]
def parse_value_syntax(string):
value_string =,string).group()
value = float(value_string.replace(',',''))
return value
def money_conversion(money):
if money == 'N/A':
return None
if isinstance(money,list):
money = money[0]
word_syntax =,money,flags=re.I)
value_syntax =,money)
if word_syntax:
print('converting word object to numerics')
return parse_word_syntax(
elif value_syntax:
print('converting float objects to numerics')
return parse_value_syntax(
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment