← 返回题库
初级

加载账单流水并统计

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    txs = pd.read_csv(StringIO(open_url("https://data.zuihe.com/dbd/ms-ledger/state_02/transactions.csv").read()))
    print(f"Total: {len(txs)}")
    print(f"Total amount: {round(txs['amount'].sum(),2)} CNY")
    print(f"Avg: {round(txs['amount'].mean(),2)} CNY")
    print(f"Manual: {len(txs[txs['is_manual']==1])} | From receipts: {len(txs[txs['receipt_id']!=''])}")
    print(f"By payment: {dict(txs.groupby('payment_method').size())}")

示例

输入
solve()
期望输出
Total: 250
Total amount: 58990.41 CNY
Avg: 235.96 CNY
Manual: 50 | From receipts: 250
By payment: {'alipay': np.int64(61), 'card': np.int64(60), 'cash': np.int64(63), 'wechat': np.int64(66)}
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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