{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "intro",
   "metadata": {},
   "source": [
    "# 从头可运行的数据分析\n",
    "本站手写参考，不是Jupyter AI输出。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "cell-0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-15T03:33:44.908432Z",
     "iopub.status.busy": "2026-10-15T03:33:44.908269Z",
     "iopub.status.idle": "2026-10-15T03:33:44.913602Z",
     "shell.execute_reply": "2026-10-15T03:33:44.913082Z"
    }
   },
   "outputs": [],
   "source": [
    "import csv\n",
    "with open(\"readings.csv\") as source:\n",
    " readings=[{\"device_id\":r[\"device_id\"],\"minutes\":int(r[\"minutes\"])} for r in csv.DictReader(source)]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "cell-1",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-15T03:33:44.915087Z",
     "iopub.status.busy": "2026-10-15T03:33:44.914966Z",
     "iopub.status.idle": "2026-10-15T03:33:44.917612Z",
     "shell.execute_reply": "2026-10-15T03:33:44.916960Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "60\n"
     ]
    }
   ],
   "source": [
    "total = sum(r[\"minutes\"] for r in readings)\n",
    "print(total)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "cell-2",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-10-15T03:33:44.918817Z",
     "iopub.status.busy": "2026-10-15T03:33:44.918712Z",
     "iopub.status.idle": "2026-10-15T03:33:44.920798Z",
     "shell.execute_reply": "2026-10-15T03:33:44.920335Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "rows=4 total=60 mean=15\n"
     ]
    }
   ],
   "source": [
    "assert len(readings)==4\n",
    "assert total==60\n",
    "assert total/len(readings)==15\n",
    "print(\"rows=4 total=60 mean=15\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
