← 返回题库
初级

统计订单状态与配送方式分布

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    orders=pd.read_csv(StringIO(open_url("https://data.zuihe.com/dbd/ms-campustrade/state_01/orders.csv").read()))
    print(f"Total orders: {len(orders)}")
    print(f"By status: {dict(orders.groupby('status').size())}")
    print(f"By delivery_method: {dict(orders.groupby('delivery_method').size())}")
    print(f"Avg price: {round(orders['price'].mean(),1)}")

示例

输入
solve()
期望输出
Total orders: 50
By status: {'completed': np.int64(28), 'disputed': np.int64(6), 'paid': np.int64(5), 'pending': np.int64(1), 'shipped': np.int64(10)}
By delivery_method: {'express': np.int64(18), 'self_pickup': np.int64(32)}
Avg price: 87.0
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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