← 返回题库
中级

实现设备数据分区键设计

未完成
中级参考 代码结构已给出,请填写 ____ 处
def solve():
    from pyodide.http import open_url
    from io import StringIO
    import pandas as pd
    readings_csv = open_url(____).read()
    readings = pd.read_csv(StringIO(____))
    import datetime
    def get_partition_key(____):
        date_str = datetime.datetime.utcfromtimestamp(____).strftime(____)
        prefix = device_id[:____]
        return prefix + '____' + date_str
    readings = readings.copy()
    readings['____'] = readings.apply(lambda r: get_partition_key(____), axis=____)
    partition_sizes = readings.groupby(____).size()
    print(____)
    for pk, count in partition_sizes.items():
        print("____" + pk + "____" + str(____) + "____")
    print("____" + str(len(____)))
    print("____" + str(round(partition_sizes.mean(),____)))

示例

输入
solve()
期望输出
Partition distribution:
  ARD_20250601: 48 records
  ARD_20250602: 48 records
  ARD_20250603: 48 records
  ESP_20250601: 32 records
  ESP_20250602: 32 records
  ESP_20250603: 32 records
  GW-_20250601: 8 records
  GW-_20250602: 8 records
  GW-_20250603: 8 records
  PLC_20250601: 16 records
  PLC_20250602: 16 records
  PLC_20250603: 16 records
  RPI_20250601: 72 records
  RPI_20250602: 72 records
  RPI_20250603: 72 records
Total partitions: 15
Avg records/partition: 35.2
Python 代码 🔒 登录后使用
🔒

登录后即可练习

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