data를 표로 만들기

def add_company(code):
  company = yf.Ticker(code)
  name = company.info['shortName']
  industry = company.info['industry']
  bussiness = company.info['longBusinessSummary']
  marketCap= company.info['marketCap']
  currentPrice= company.info['currentPrice']
  targetPrice= company.info['targetMeanPrice']
  per = company.info['forwardPE']
  eps = company.info['forwardEps']
  pbr = company.info['priceToBook']
  rev2021 = company.earnings.iloc[-1,0]
  rev2020 = company.earnings.iloc[-2,0]
  rev2019 = company.earnings.iloc[-3,0]
  ear2021 = company.earnings.iloc[-1,1]
  ear2020 = company.earnings.iloc[-2,1]
  ear2019 = company.earnings.iloc[-3,1]

  doc = {
    'code':code,
    'name':name,
    'industry':industry,
    'bussiness':bussiness,
    'marketCap':marketCap/1000,
    'currentPrice':currentPrice,
    'targetPrice':targetPrice,
    'per':per,
    'eps':eps,
    'pbr':pbr,
    'rev2021':rev2021/1000,
    'rev2020':rev2020/1000,
    'rev2019':rev2019/1000,
    'ear2021':ear2021/1000,
    'ear2020':ear2020/1000,
    'ear2019':ear2019/1000,
  }
  return doc
  
  df = pd.DataFrame()
codes = ['AAPL','ABNB','BIDU','FB','GOOG','MSFT','TSLA','PYPL','NFLX','NVDA']

for code in codes:
   print(code)
   try: 
    row = add_company (code)
    df.append(row,ignore_index=True)
   except:
    print(f'error -{code}')
df

 

 

'기술' 카테고리의 다른 글

DART open api 개발가이드  (0) 2022.11.08
DART openAPI 이용 금융데이타 분석  (0) 2022.11.07
yfinance 분석  (0) 2022.11.06
Pandas (11/6)  (0) 2022.11.06
RealtimeDatabase 정보확인  (0) 2022.11.05