← 返回题库
初级

分析卡片主题标签使用分布

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    cards=pd.read_csv(StringIO(open_url("https://data.zuihe.com/dbd/ms-memcard/state_00/cards.csv").read()))
    tag_dist=cards.groupby('tags').size().reset_index(name='count').sort_values('count',ascending=False)
    total=len(cards)
    print("Tag distribution:")
    for _,r in tag_dist.iterrows():
        bar='x'*int(r['count']/total*20)
        print(f"  {r['tags']:<15}: {bar} {r['count']} ({round(r['count']/total*100,1)}%)")

示例

输入
solve()
期望输出
Tag distribution:
  programming    : xxxx 417 (22.5%)
  en_vocab       : xx 206 (11.1%)
  math           : xx 201 (10.9%)
  ja_vocab       : x 182 (9.8%)
  es_vocab       : x 150 (8.1%)
  history        : x 120 (6.5%)
  movies         : x 106 (5.7%)
  geography      : x 105 (5.7%)
  quotes         :  76 (4.1%)
  law            :  70 (3.8%)
  medical        :  61 (3.3%)
  accounting     :  47 (2.5%)
  physics        :  40 (2.2%)
  chemistry      :  36 (1.9%)
  biology        :  35 (1.9%)
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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