{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1b5c6199",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "# 读取数据集 2分\n",
    "data = _____________"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6850013d",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1. 传感器数据统计\n",
    "# 对传感器类型进行分组，并计算每个组的数据数量和平均值 3分\n",
    "sensor_stats = _____________(_____________)['Value']._____________\n",
    "# 输出结果\n",
    "print(\"传感器数据数量和平均值:\")\n",
    "print(sensor_stats)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "eacd7337",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 2. 按位置统计温度和湿度数据\n",
    "# 筛选出温度和湿度数据，然后按位置和传感器类型分组，计算每个组的平均值 2分\n",
    "location_stats = data[data['SensorType']._____________._____________['Value'].mean().unstack()\n",
    "# 输出结果\n",
    "print(\"每个位置的温度和湿度数据平均值:\")\n",
    "print(location_stats)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d51f5518",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 3. 数据清洗和异常值处理\n",
    "# 标记异常值 3分\n",
    "data['is_abnormal'] = _____________(\n",
    "    ((_____________) & ((data['Value'] < -10) | (data['Value'] > 50))) |\n",
    "    ((_____________) & ((data['Value'] < 0) | (data['Value'] > 100))),\n",
    "    True, False\n",
    ")\n",
    "# 输出异常值数量 2分\n",
    "print(\"异常值数量:\", data['is_abnormal']._____________)\n",
    "# 填补缺失值\n",
    "# 使用前向填充和后向填充的方法填补缺失值 4分\n",
    "data['Value']._____________(_____________, inplace=True)\n",
    "data['Value']._____________(_____________, inplace=True)\n",
    "# 保存清洗后的数据\n",
    "# 删除用于标记异常值的列，并将清洗后的数据保存到新的CSV文件中 4分\n",
    "cleaned_data = _____________(_____________=['is_abnormal'])\n",
    "_____________('cleaned_sensor_data.csv', _____________)\n",
    "print(\"数据清洗完成，已保存为 'cleaned_sensor_data.csv'\")"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
