Skip to content

Commit

Permalink
improved market cap value extraction (#5169)
Browse files Browse the repository at this point in the history
* improved market cap value extraction

* pylint

---------

Co-authored-by: James Maslek <[email protected]>
  • Loading branch information
bimbolimbo and jmaslek authored Nov 8, 2023
1 parent cfc40e7 commit acf8b06
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,18 +343,19 @@ def get_market_cap(symbol) -> float:
latest_year = market_cap.index[-1]

value = market_cap.loc[latest_year]["Market capitalization"]

if "M" in value:
updated_value = float(value.split(" M")[0]) * 1000000
elif "B" in value:
updated_value = float(value.split(" B")[0]) * 1000000000
elif "T" in value:
updated_value = float(value.split(" T")[0]) * 1000000000000
values_str = str(value)

# use values_str in string operations
if values_str.endswith("M"):
updated_value = float(values_str.split(" M", maxsplit=1)[0]) * 1000000
elif values_str.endswith("B"):
updated_value = float(values_str.split(" B", maxsplit=1)[0]) * 1000000000
elif values_str.endswith("T"):
updated_value = float(values_str.split(" T", maxsplit=1)[0]) * 1000000000000
else:
updated_value = float(value)
updated_value = float(values_str)
else:
updated_value = 0

return updated_value


Expand Down

0 comments on commit acf8b06

Please sign in to comment.