Click here to Skip to main content
15,353,432 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
After days of trying, I still can't format the 'mktCap' to make it easier to read (either add in commas or convert it to million). My code is as below:

pip install FundamentalAnalysis


import pandas as pd
import FundamentalAnalysis as fa

pd.set_option('display.max_colwidth',0)
pd.options.display.float_format = '{:,.2f}'.format

ticker = 'AAPL'
api_key = "04d9e13fe10d09ef72be8bbd0e21262e"

# Collect general company information
profile = fa.profile(ticker, api_key)
print(profile.loc[['symbol','companyName','mktCap','range','changes',\
                   'exchangeShortName','industry','sector','description',\
                   'ceo','fullTimeEmployees','state','isActivelyTrading']])
print('')
 
# Show the growth of the company
growth_annually = fa.financial_statement_growth(ticker, api_key, period="annual")
nig = growth_annually.loc['netIncomeGrowth']
 
# Show a large set of in-depth ratios
financial_ratios_annually = fa.financial_ratios(ticker, api_key, period="annual")
dy = financial_ratios_annually.loc['dividendYield'] 
pe = financial_ratios_annually.loc['priceEarningsRatio']
npm = financial_ratios_annually.loc['netProfitMargin']
roe = financial_ratios_annually.loc['returnOnEquity']
cf = financial_ratios_annually.loc['freeCashFlowOperatingCashFlowRatio']
atr = financial_ratios_annually.loc['assetTurnover']
em = financial_ratios_annually.loc['companyEquityMultiplier']
 
df = pd.DataFrame([nig, dy, pe, npm, roe, cf, atr, em])
df['Ult + DuPont'] = ['G:Net Inc Gr', 'D:DY', 'P:P/E', 'P:NPM', 'R:ROE', \
                      'C:Free CF/Op CF','Asset Turnover','Equity Mult']
df = df.set_index('Ult + DuPont')
print(df[df.columns[:5]])
print('')
 
# Obtain DCFs over time
dcf_annually = fa.discounted_cash_flow(ticker, api_key, period="annual")
dcf_quarterly = fa.discounted_cash_flow(ticker, api_key, period="quarter")
print(dcf_annually.iloc[:,:5])
print('')
print(dcf_quarterly.iloc[:,:5])
print('')
 
# Show recommendations of Analysts
ratings = fa.rating(ticker, api_key)
print(ratings)
print('')


May I know how to convert the reading for 'mktCap' to make it easier to read? Thanks.

What I have tried:

numerize
millify
prettify
astype
pd.to_numeric
Posted
Updated 13-Mar-21 3:08am
v2

1 solution

Use the float() built in function[^] to convert the integer to a float.
   
Comments
Member 13986926 13-Mar-21 8:24am
   
Thanks for the advice. I retrieve the data from API and print out in table as below:
symbol AAPL
.......
mktCap 2031863730000
May I know how to apply float() to 2031863730000 for mktCap? Thanks.
Richard MacCutchan 13-Mar-21 8:51am
   
It is very difficult to provide advice when your question is so vague. You have not really explained clearly what you are trying to do.
Member 13986926 13-Mar-21 8:55am
   
True. Let me put the whole code in the solution part below as I can't post a long post under reply.
Richard MacCutchan 13-Mar-21 8:57am
   
No, Please use the Improve question link above.
Member 13986926 13-Mar-21 9:03am
   
Ok, will do accordingly.
Richard MacCutchan 13-Mar-21 8:54am
   
    mktCap = 2031863730000
    print(float(mktCap))

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900