初级
解析小票条目并计算合计
未完成
初级参考
完整示例代码供参考,建议自己理解后重新输入
def solve():
from pyodide.http import open_url
from io import StringIO
import pandas as pd
items = pd.read_csv(StringIO(open_url("https://data.zuihe.com/dbd/ms-ledger/state_01/receipt_items.csv").read()))
print(f"Total items: {len(items)}")
by_rcp = items.groupby('receipt_id').agg(count=('item_id','count'),total=('subtotal','sum')).reset_index()
by_rcp['total'] = by_rcp['total'].round(2)
print(f"Receipts with items: {len(by_rcp)}")
print(f"Avg items/receipt: {round(by_rcp['count'].mean(),1)}")
for _, row in by_rcp.head(5).iterrows():
print(f" {row['receipt_id']}: {row['count']} items total={row['total']}")
示例
输入
solve()
期望输出
Total items: 345 Receipts with items: 200 Avg items/receipt: 1.7 RCP-00001: 1 items total=245.58 RCP-00002: 3 items total=473.7 RCP-00003: 1 items total=464.82 RCP-00004: 1 items total=337.5 RCP-00005: 1 items total=36.68
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199