← 返回题库
初级

统计平台评分分布与低评分商家排行

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    reviews=pd.read_csv(StringIO(open_url("https://data.zuihe.com/dbd/ms-takeaway/state_04/reviews.csv").read()))
    print(f"Total reviews: {len(reviews)}")
    print(f"Avg merchant_rating: {round(reviews['merchant_rating'].mean(),2)}")
    print(f"1-star reviews: {len(reviews[reviews['merchant_rating']==1])}")
    print(f"5-star reviews: {len(reviews[reviews['merchant_rating']==5])}")
    by_merchant=reviews.groupby('merchant_id')['merchant_rating'].mean().round(2).nsmallest(5)
    print("Lowest rated merchants (avg):")
    for mid,avg in by_merchant.items():
        print(f"  {mid}: {avg}")

示例

输入
solve()
期望输出
Total reviews: 81
Avg merchant_rating: 4.26
1-star reviews: 1
5-star reviews: 39
Lowest rated merchants (avg):
  MER-0004: 3.5
  MER-0006: 3.5
  MER-0007: 4.0
  MER-0012: 4.0
  MER-0005: 4.17
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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