开始使用免费开始使用

按行业计算比率

在本练习中,您将评估科技(Tech)和快速消费品(FMCG)公司的流动比率与资产负债率(debt-to-equity ratio)在平均水平上的差异,以及它们随时间的变化。

行业比率的「平均」值可以帮助我们把握该行业的整体财务状况。而行业比率随「时间」的变化有助于理解其趋势:该比率是否相对稳定,还是随时间波动?是在改善还是在恶化?

balance_sheet 已作为一个 pandas DataFrame 为您加载。流动比率位于 curr_ratio 列,资产负债率位于 debt_to_equity 列。pandas 已以别名 pd 导入。

本练习是课程的一部分

用 Python 分析财务报表

查看课程

练习说明

  • 选取 comp_type 列为 techfmcg 的公司。
  • 使用 .groupby() 按公司类型(由 "comp_type" 列表示)分组,计算平均流动比率与资产负债率。
  • 使用 .groupby() 同时按 "comp_type""Year" 分组,计算平均流动比率与资产负债率。

交互式实操练习

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

# Choose the tech and fmcg companies
tech_fmcg = balance_sheet.loc[balance_sheet[____].isin(____)]

# Compute the average debt-to-equity ratio and current ratio by industry
groupby_industry = tech_fmcg.____(____)[["current_ratio", "debt_to_equity"]].____

# Compute the average debt-to-equity ratio and current ratio by industry and over time
groupby_industry_time = tech_fmcg.____(____)[["current_ratio", "debt_to_equity"]].____

print(groupby_industry)
print(groupby_industry_time)
编辑并运行代码