开始使用免费开始使用

按行业与 IPO 年份计算多项指标

seabornpointplot() 函数可用于比较数值变量在不同分类变量水平下的统计汇总:

seaborn.pointplot(x=None, y=None, hue=None, data=None, ...)

在视频中,您看到一个可视化图,将市值(数值变量)按 IPO(分类变量)是否发生在 2000 年之前(第一层级)或之后(第二层级)进行区分。

在本练习中,您将比较自 2000 年以来,每一年 NYSE 与 NASDAQ 的平均市值,并排除高于第 95 个百分位的离群值。已导入 pandaspdmatplotlib.pyplotplt,工作区中提供了带有参考列 'Exchange'listings 数据框。

本练习是课程的一部分

在 Python 中导入与管理金融数据

查看课程

练习说明

  • 导入 seabornsns
  • listings 过滤为所有交易所中 IPO 年份在 2000 年之后、且不包含 'amex' 的公司。
  • 'IPO Year' 列中的数据转换为整数。
  • 创建列 market_cap_m,用来表示以百万美元计的市值。
  • market_cap_m 中过滤掉高于第 95 个百分位的值。
  • 使用 pointplot 基于 listings 绘图:x 使用 'IPO Year'y 使用 'market_cap_m'hue 使用 'Exchange'。将 xticks 旋转 45 度后显示结果。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Import the seaborn library as sns
____

# Exclude IPOs before 2000 and from the 'amex'
listings = ____[(____['IPO Year'] > ____) & (listings.Exchange != ____)]

# Convert IPO Year to integer
listings['IPO Year'] = ____['IPO Year'].____(____)

# Create market_cap_m
listings['market_cap_m'] = ____['Market Capitalization'].div(1e6)

# Exclude outliers
listings = listings[listings.____ < listings.____.____(.95)]

# Create the pointplot
sns.pointplot(x=____, y=____, hue=____, data=____)

# Rotate xticks
plt.____(____=____)

# Show the plot
plt.show()
编辑并运行代码