← 返回题库
中级

统计同分类商家消费对比

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    txs = pd.read_csv(StringIO(open_url(____).read()))
    by_mch = txs.groupby(____).agg(total=(____),count=(____),avg=(____)).reset_index()
    for cat in ['____','____','____']:
        top = by_mch[by_mch['____']==cat].nlargest(____,'____')
        print(____)
        for _, row in top.iterrows():
            print(____)

示例

输入
solve()
期望输出
CAT-01:
    西贝莜面村: total=1434.34 count=4 avg=358.58
    肯德基: total=972.39 count=4 avg=243.1
    必胜客: total=790.48 count=4 avg=197.62
  CAT-02:
    奈雪的茶: total=1708.92 count=6 avg=284.82
    喜茶: total=1645.76 count=6 avg=274.29
    瑞幸咖啡: total=1472.48 count=5 avg=294.5
  CAT-03:
    叮咚买菜: total=747.24 count=3 avg=249.08
    沃尔玛: total=656.76 count=3 avg=218.92
    手动录入: total=462.85 count=3 avg=154.28
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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