0

I created a python script to scrape Yahoo finance to extract some data; so created a method that extract a table and display it as a pandas table for example;

f = get_stock_info('AAPL') with output

                               Value
Label                               
Market Cap (intraday) 5       815.6B
Enterprise Value 3           834.29B
Trailing P/E                   14.27
Forward P/E 1                  13.57
PEG Ratio (5 yr expected) 1     1.15
Price/Sales (ttm)               3.12
Price/Book (mrq)                6.94
Enterprise Value/Revenue 3      3.19
Enterprise Value/EBITDA 6      10.49

I would like to be able to transform this table from object to Float type so I would need to get rid of the B in 815.6B and 834.29B

I tried:

x = f.loc["Market Cap (intraday) 5"][0][:-1]

which output 815.6

then f.loc["Market Cap (intraday) 5"][0] = f.loc["Market Cap (intraday) 5"][0][:-1]

but the output is 815 and not 816.6

Any idea how to solve it ?

Ben2pop
  • 746
  • 1
  • 10
  • 26

0 Answers0