初级
统计各设备缓存命中率
未完成
初级参考
完整示例代码供参考,建议自己理解后重新输入
def solve():
from pyodide.http import open_url
from io import StringIO
import pandas as pd
cache_csv = open_url("https://data.zuihe.com/dbd/ms-iot/state_07/cache_log.csv").read()
cache = pd.read_csv(StringIO(cache_csv))
reads = cache[cache['operation']=='read'].copy()
reads['device_id'] = reads['cache_key'].str.split(':').str[1]
print("Cache hit rate by device:")
for did, grp in reads.groupby('device_id'):
hr = grp['hit'].mean()
print(" " + did + ": " + str(round(hr*100,1)) + "% (" + str(int(grp['hit'].sum())) + "/" + str(len(grp)) + ")")
total_hr = reads['hit'].mean()
print("Overall hit rate: " + str(round(total_hr*100,1)) + "%")
示例
输入
solve()
期望输出
Cache hit rate by device: DEV001: 75.0% (3/4) DEV002: 0.0% (0/1) DEV004: 100.0% (5/5) DEV005: 50.0% (1/2) DEV007: 0.0% (0/1) DEV010: 100.0% (3/3) Overall hit rate: 75.0%
👑
升级 VIP
解锁全部题目,畅通无阻地学习
- ✓ 解锁全部训练包所有题目
- ✓ 查看完整参考代码和提示
- ✓ 浏览器内直接运行 Python 代码
- ✓ 自动批改 + 进度追踪
30天
¥18
1年
¥99
2年
¥158
3年
¥199