← 返回题库
初级

现金流分析:三类现金流增长率趋势对比

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
"""
金融风险管理 - q041
现金流异常分析:三类现金流增长率趋势对比
"""

metadata = {
    "id": "q041",
    "title": "现金流分析:三类现金流增长率趋势对比",
    "module": "现金流异常分析",
    "difficulty": "beginner",
    "data_files": ["case34_yutong_operating.csv"],
    "skills": ["增长率计算", "趋势对比", "现金流结构"],
    "estimated_minutes": 8
}

"""
【题目】
读取case34_yutong_operating.csv,分析宇通客车营收、利润、现金流三者增长率的趋势。

数据已包含 revenue_growth、profit_growth、ocf_growth 字段。

输出DataFrame,index为year,包含:revenue_growth、profit_growth、ocf_growth
并追加一列"现金流背离":若ocf_growth与profit_growth差异绝对值>0.5,标记"⚠ 背离",否则"一致"

所有增长率保留4位小数。
"""

def solve():
    import pandas as pd
    from pyodide.http import open_url
    from io import StringIO

    BASE_URL = "https://data.zuihe.com/finance/"
    df = pd.read_csv(StringIO(open_url(BASE_URL + "case34_yutong_operating.csv").read()))

    df = df.set_index('year')
    df['现金流背离'] = df.apply(
        lambda r: '⚠ 背离' if abs(r['ocf_growth'] - r['profit_growth']) > 0.5 else '一致', axis=1)

    result = df[['revenue_growth', 'profit_growth', 'ocf_growth', '现金流背离']]
    return result.to_string()

if __name__ == "__main__":
    print(solve())

示例

输入
solve()
期望输出
revenue_growth  profit_growth  ocf_growth 现金流背离 | year                                                  | 2007           45.83          97.80      -25.22  ⚠ 背离 | 2008            3.51          16.70       40.73  ⚠ 背离 | 2009            5.35           8.21      -92.43  ⚠ 背离
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码