計算流通在外股數
建立市值加權指數的下一步,是計算每個指數成分股的流通在外股數。
有了股數,你就能在下一個練習中,搭配歷史價格時間序列,計算各成分股的總市值。
本練習屬於課程
Manipulating Time Series Data in Python
練習說明
我們已經像前面練習一樣,將 pandas 以 pd 匯入,並準備好 tickers 與 listings。
- 先檢視
listings,並印出tickers。 - 使用
.loc[]搭配tickers的清單,擷取指數成分股,並選取欄位'Market Capitalization'與'Last Sale';將結果指定為components。 - 印出
components的前 5 列。 - 以
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(____)