발행 주식 수 계산하기
가치 가중 지수를 구축하는 다음 단계는 각 지수 구성 종목의 주식 수를 계산하는 것입니다.
주식 수를 구하면, 다음 연습 문제에서 과거 가격 시계열 데이터를 활용해 각 구성 종목의 총 시가총액을 계산할 수 있습니다.
이 연습은 강의의 일부입니다
Python으로 시계열 데이터 다루기
연습 안내
pandas는 pd로, tickers와 listings는 이전 연습 문제와 동일하게 이미 임포트되어 있습니다.
listings를 살펴보고tickers를 출력하세요..loc[]에tickers리스트를 사용하여 지수 구성 종목과'Market Capitalization','Last Sale'열을 선택한 후, 결과를components에 할당하세요.components의 처음 다섯 행을 출력하세요.Market Capitalization을'Last Sale'로 나누어no_shares를 생성하세요.no_shares를 내림차순으로 출력하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
# Inspect listings and print tickers
print(____)
print(____)
# Select components and relevant columns from listings
components = ____
# Print the first rows of components
print(____)
# Calculate the number of shares here
no_shares = ____
# Print the sorted no_shares
print(____)