← 返回题库
初级

综合买卖次数找出平台最活跃用户

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    user_stats=pd.read_csv(StringIO(open_url("https://data.zuihe.com/dbd/ms-campustrade/state_04/user_stats.csv").read()))
    user_stats['activity_score']=user_stats['buy_count']+user_stats['sell_count']
    print("Top 5 most active users:")
    for _,r in user_stats.nlargest(5,'activity_score').iterrows():
        print(f"  {r['name']}: buy={r['buy_count']} sell={r['sell_count']} credit={r['credit_score']} score={r['activity_score']}")

示例

输入
solve()
期望输出
Top 5 most active users:
  何勇: buy=2 sell=4 credit=78 score=6
  徐敏: buy=4 sell=1 credit=80 score=5
  孙超: buy=2 sell=3 credit=89 score=5
  胡涛: buy=3 sell=1 credit=100 score=4
  罗平: buy=3 sell=0 credit=93 score=3
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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