Last active
October 31, 2023 19:41
-
-
Save gajeshbhat/67a3db79a6aecd1db42343190f9a2f17 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_str_to_number(x): | |
total_stars = 0 | |
num_map = {'K':1000, 'M':1000000, 'B':1000000000} | |
if x.isdigit(): | |
total_stars = int(x) | |
else: | |
if len(x) > 1: | |
total_stars = float(x[:-1]) * num_map.get(x[-1].upper(), 1) | |
return int(total_stars) |
s3rgeym
commented
Oct 31, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment