开始使用免费开始使用

计算流通股数

构建市值加权指数的下一步是为每个成分股计算流通股数。

在下一个练习中,给定历史价格序列,流通股数将帮助您计算每个成分股的总市值。

本练习是课程的一部分

Python 中的时间序列数据处理

查看课程

练习说明

我们已经像之前的练习一样导入了 pandaspd,并加载了 tickerslistings

  • 查看 listings 并打印 tickers
  • 使用带有 tickers 列表的 .loc[] 选择指数成分股以及列 '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(____)
编辑并运行代码