可视化财务比率以便比较

用 Python 分析财务报表

Rohan Chatterjee

Risk Modeler

绘制两家公司的比率

sns.set_style("whitegrid")
ax = sns.lineplot(data=current_ratio,
        x="Year",y='current_ratio',
        hue="company", alpha=0.7)
plt.xlabel("Year")
plt.ylabel("Current Ratio")

此图展示了可口可乐与百事可乐在 2008–2020 年的流动比率。

用 Python 分析财务报表

使用 sns.lineplot() 时的拥挤问题

该图在很小空间内包含过多信息,显得拥挤 此图在一张图中展示了可口可乐与百事可乐的资产负债率、流动比率、速动比率和毛利率,画面非常拥挤。

用 Python 分析财务报表

介绍 sns.relplot()

  • 第一步:对 DataFrame 执行 melt,得到长格式数据。

  • "未 melt"的 DataFrame:

plot_df.head()

该图显示了一个宽格式 DataFrame。

用 Python 分析财务报表

现在对 DataFrame 执行 melt

plot_df_melt = plot_df.melt(id_vars = ['company','Year'], var_name = "Ratio")

该图显示了一个已 melt 的 DataFrame 的前几行。

用 Python 分析财务报表

使用 sns.relplot() 绘制比率

ax = sns.relplot(data=df_melt, x="Year",
                 y="value", hue="Ratio",
                 alpha=0.7,
                 col='company',
                 kind='line')
ax.set_ylabels('')
ax.set_xlabels('')

此图展示了可口可乐与百事可乐的资产负债率、流动比率、速动比率和毛利率;两家公司的比率分列在两个面板中。

用 Python 分析财务报表

放大查看图表

此图展示了可口可乐与百事可乐的资产负债率、流动比率、速动比率和毛利率;两家公司的比率分列在两个面板中。

用 Python 分析财务报表

Passons à la pratique !

用 Python 分析财务报表

Preparing Video For Download...