← 返回题库
初级

财务舞弊识别:扣非净利润连续为负分析

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
"""
金融风险管理 - q053
财务舞弊识别:扣非净利润连续为负
"""

metadata = {
    "id": "q053",
    "title": "财务舞弊识别:扣非净利润连续为负分析",
    "module": "财务舞弊识别",
    "difficulty": "beginner",
    "data_files": ["case35_company_profit.csv"],
    "skills": ["扣非分析", "连续亏损", "舞弊红旗"],
    "estimated_minutes": 8
}

"""
【题目】
读取case35_company_profit.csv,分析圣莱达扣非净利润连续为负的特征:

1. 标记每年扣非净利润为负的年份
2. 计算非经常性损益 = net_profit - deducted_profit
3. 计算依赖非经常项"维持表面盈利"的程度

输出DataFrame,包含:year、revenue、net_profit、deducted_profit、
非经常性损益、扣非是否亏损、维持盈利来源

维持盈利来源:若net_profit>0且deducted_profit<0,标记"依赖非经常项";
若两者都<0,标记"全面亏损";否则"正常盈利"
"""

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 + "case35_company_profit.csv").read()))

    df['非经常性损益'] = df['net_profit'] - df['deducted_profit']
    df['扣非是否亏损'] = df['deducted_profit'].apply(lambda x: '⚠ 亏损' if x < 0 else '盈利')

    def source(row):
        if row['net_profit'] > 0 and row['deducted_profit'] < 0:
            return '依赖非经常项'
        elif row['net_profit'] < 0 and row['deducted_profit'] < 0:
            return '全面亏损'
        else:
            return '正常盈利'

    df['维持盈利来源'] = df.apply(source, axis=1)
    result = df[['year', 'revenue', 'net_profit', 'deducted_profit',
                 '非经常性损益', '扣非是否亏损', '维持盈利来源']]
    return result.to_string()

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

示例

输入
solve()
期望输出
year   revenue  net_profit  deducted_profit   非经常性损益 扣非是否亏损  维持盈利来源 | 0  2010  23388.43     3389.17          2753.22   635.95     盈利    正常盈利 | 1  2011  22822.61     1897.25          1589.89   307.36     盈利    正常盈利 | 2  2012  20512.75     2184.43          1547.62   636.81     盈利    正常盈利 | 3  2013  16612.78      298.70            82.43   216.27     盈利    正常盈利 | 4  2014  15096.79    -1009.56         -1046.65    37.09   ⚠ 亏损    全面亏损 | 5  2015  10523.02      344.26         -1522.40  1866.66   ⚠ 亏损  依赖非经常项
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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