-
-
Save asadamatic/a0077b28369f5fbe7539cdbac898cc74 to your computer and use it in GitHub Desktop.
Convert k to Integer thousand Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def convert_si_to_number(x): | |
total_stars = 0 | |
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 | |
elif ',' in x: | |
total_stars = float(x.replace(',','')) # removing , | |
else: | |
total_stars = int(x) # Less than 1000 | |
return int(total_stars) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment