Damn, a quick google search finds:
def convert_si_to_number(x):
total_stars = 0
x = x.replace('€', '')
if 'k' in x:
if len(x) > 1:
total_stars = float(x.replace('k', '')) * 1000 # convert k to a thousand
elif 'M' in x:
if len(x) > 1:
total_stars = float(x.replace('M', '')) * 1000000 # convert M to a million
elif 'B' in x:
total_stars = float(x.replace('B', '')) * 1000000000 # convert B to a Billion
else:
total_stars = int(x) # Less than 1000
return int(total_stars)
An easy way to apply to a df is run it on a loop
for i, stringo in enumerate(file):
file[i] = convert_si_to_number(stringo)
4
solved Convert pandas column with currency values like €118.5M or €60K to integers or floats [closed]