{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "ed7a1260",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pandas in c:\\programdata\\anaconda3\\lib\\site-packages (1.4.2)\n",
      "Requirement already satisfied: matplotlib in c:\\programdata\\anaconda3\\lib\\site-packages (3.5.1)\n",
      "Requirement already satisfied: python-dateutil>=2.8.1 in c:\\programdata\\anaconda3\\lib\\site-packages (from pandas) (2.8.2)\n",
      "Requirement already satisfied: pytz>=2020.1 in c:\\programdata\\anaconda3\\lib\\site-packages (from pandas) (2021.3)\n",
      "Requirement already satisfied: numpy>=1.18.5 in c:\\programdata\\anaconda3\\lib\\site-packages (from pandas) (1.21.5)\n",
      "Requirement already satisfied: pillow>=6.2.0 in c:\\programdata\\anaconda3\\lib\\site-packages (from matplotlib) (9.0.1)\n",
      "Requirement already satisfied: fonttools>=4.22.0 in c:\\programdata\\anaconda3\\lib\\site-packages (from matplotlib) (4.25.0)\n",
      "Requirement already satisfied: kiwisolver>=1.0.1 in c:\\programdata\\anaconda3\\lib\\site-packages (from matplotlib) (1.3.2)\n",
      "Requirement already satisfied: pyparsing>=2.2.1 in c:\\programdata\\anaconda3\\lib\\site-packages (from matplotlib) (3.0.4)\n",
      "Requirement already satisfied: cycler>=0.10 in c:\\programdata\\anaconda3\\lib\\site-packages (from matplotlib) (0.11.0)\n",
      "Requirement already satisfied: packaging>=20.0 in c:\\programdata\\anaconda3\\lib\\site-packages (from matplotlib) (21.3)\n",
      "Requirement already satisfied: six>=1.5 in c:\\programdata\\anaconda3\\lib\\site-packages (from python-dateutil>=2.8.1->pandas) (1.16.0)\n"
     ]
    }
   ],
   "source": [
    "#任务2.1  jupyter安装软件\n",
    "!pip install pandas matplotlib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7bb16fb9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n",
      "Collecting selenium\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/74/9e/642a355e43a4ebf68bc4f00dd4ab264f635079c5dc7ed6d9991a0c2be3d7/selenium-4.36.0-py3-none-any.whl (9.6 MB)\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.\n",
      "conda-repo-cli 1.0.4 requires pathlib, which is not installed.\n",
      "anaconda-project 0.10.2 requires ruamel-yaml, which is not installed.\n",
      "requests 2.27.1 requires urllib3<1.27,>=1.21.1, but you have urllib3 2.6.3 which is incompatible.\n",
      "jupyter-server 1.13.5 requires pywinpty<2; os_name == \"nt\", but you have pywinpty 2.0.2 which is incompatible.\n",
      "botocore 1.24.32 requires urllib3<1.27,>=1.25.4, but you have urllib3 2.6.3 which is incompatible.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Collecting certifi>=2025.6.15\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/22/30/7cd8fdcdfbc5b869528b079bfb76dcdf6056b1a2097a662e5e8c04f42965/certifi-2026.4.22-py3-none-any.whl (135 kB)\n",
      "Collecting typing_extensions<5.0,>=4.14.0\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/18/67/36e9267722cc04a6b9f15c7f3441c2363321a3ea07da7ae0c0707beb2a9c/typing_extensions-4.15.0-py3-none-any.whl (44 kB)\n",
      "Collecting trio-websocket<1.0,>=0.12.2\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/c7/19/eb640a397bba49ba49ef9dbe2e7e5c04202ba045b6ce2ec36e9cadc51e04/trio_websocket-0.12.2-py3-none-any.whl (21 kB)\n",
      "Collecting trio<1.0,>=0.30.0\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/31/5b/94237a3485620dbff9741df02ff6d8acaa5fdec67d81ab3f62e4d8511bf7/trio-0.31.0-py3-none-any.whl (512 kB)\n",
      "Collecting urllib3[socks]<3.0,>=2.5.0\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/39/08/aaaad47bc4e9dc8c725e68f9d04865dbcb2052843ff09c97b08904852d84/urllib3-2.6.3-py3-none-any.whl (131 kB)\n",
      "Collecting websocket-client<2.0,>=1.8.0\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/34/db/b10e48aa8fff7407e67470363eac595018441cf32d5e1001567a7aeba5d2/websocket_client-1.9.0-py3-none-any.whl (82 kB)\n",
      "Collecting attrs>=23.2.0\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/64/b4/17d4b0b2a2dc85a6df63d1157e028ed19f90d4cd97c36717afef2bc2f395/attrs-26.1.0-py3-none-any.whl (67 kB)\n",
      "Requirement already satisfied: idna in c:\\programdata\\anaconda3\\lib\\site-packages (from trio<1.0,>=0.30.0->selenium) (3.3)\n",
      "Requirement already satisfied: sortedcontainers in c:\\programdata\\anaconda3\\lib\\site-packages (from trio<1.0,>=0.30.0->selenium) (2.4.0)\n",
      "Collecting sniffio>=1.3.0\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl (10 kB)\n",
      "Requirement already satisfied: cffi>=1.14 in c:\\programdata\\anaconda3\\lib\\site-packages (from trio<1.0,>=0.30.0->selenium) (1.15.0)\n",
      "Collecting exceptiongroup\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8a/0e/97c33bf5009bdbac74fd2beace167cab3f978feb69cc36f1ef79360d6c4e/exceptiongroup-1.3.1-py3-none-any.whl (16 kB)\n",
      "Collecting outcome\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/55/8b/5ab7257531a5d830fc8000c476e63c935488d74609b50f9384a643ec0a62/outcome-1.3.0.post0-py2.py3-none-any.whl (10 kB)\n",
      "Requirement already satisfied: pycparser in c:\\programdata\\anaconda3\\lib\\site-packages (from cffi>=1.14->trio<1.0,>=0.30.0->selenium) (2.21)\n",
      "Collecting wsproto>=0.14\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/78/58/e860788190eba3bcce367f74d29c4675466ce8dddfba85f7827588416f01/wsproto-1.2.0-py3-none-any.whl (24 kB)\n",
      "Requirement already satisfied: pysocks!=1.5.7,<2.0,>=1.5.6 in c:\\programdata\\anaconda3\\lib\\site-packages (from urllib3[socks]<3.0,>=2.5.0->selenium) (1.7.1)\n",
      "Collecting h11<1,>=0.9.0\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/04/4b/29cac41a4d98d144bf5f6d33995617b185d14b22401f75ca86f384e87ff1/h11-0.16.0-py3-none-any.whl (37 kB)\n",
      "Installing collected packages: typing-extensions, attrs, sniffio, outcome, h11, exceptiongroup, wsproto, urllib3, trio, websocket-client, trio-websocket, certifi, selenium\n",
      "  Attempting uninstall: typing-extensions\n",
      "    Found existing installation: typing-extensions 4.1.1\n",
      "    Uninstalling typing-extensions-4.1.1:\n",
      "      Successfully uninstalled typing-extensions-4.1.1\n",
      "  Attempting uninstall: attrs\n",
      "    Found existing installation: attrs 21.4.0\n",
      "    Uninstalling attrs-21.4.0:\n",
      "      Successfully uninstalled attrs-21.4.0\n",
      "  Attempting uninstall: sniffio\n",
      "    Found existing installation: sniffio 1.2.0\n",
      "    Uninstalling sniffio-1.2.0:\n",
      "      Successfully uninstalled sniffio-1.2.0\n",
      "  Attempting uninstall: urllib3\n",
      "    Found existing installation: urllib3 1.26.9\n",
      "    Uninstalling urllib3-1.26.9:\n",
      "      Successfully uninstalled urllib3-1.26.9\n",
      "  Attempting uninstall: websocket-client\n",
      "    Found existing installation: websocket-client 0.58.0\n",
      "    Uninstalling websocket-client-0.58.0:\n",
      "      Successfully uninstalled websocket-client-0.58.0\n",
      "  Attempting uninstall: certifi\n",
      "    Found existing installation: certifi 2021.10.8\n",
      "    Uninstalling certifi-2021.10.8:\n",
      "      Successfully uninstalled certifi-2021.10.8\n",
      "Successfully installed attrs-26.1.0 certifi-2026.4.22 exceptiongroup-1.3.1 h11-0.16.0 outcome-1.3.0.post0 selenium-4.36.0 sniffio-1.3.1 trio-0.31.0 trio-websocket-0.12.2 typing-extensions-4.15.0 urllib3-2.6.3 websocket-client-1.9.0 wsproto-1.2.0\n"
     ]
    }
   ],
   "source": [
    "#任务2.2  jupyter安装selenium软件\n",
    "!pip install selenium -i https://pypi.tuna.tsinghua.edu.cn/simple"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b08b4af2",
   "metadata": {},
   "outputs": [],
   "source": [
    "1+11"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "12e83309",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "缺失值位置标记：\n",
      "      语文     数学     英语\n",
      "0  False  False  False\n",
      "1  False  False   True\n",
      "2   True  False   True\n",
      "3  False  False  False\n"
     ]
    }
   ],
   "source": [
    "#缺失值\n",
    "# 导入库\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "# 自动生成测试成绩表\n",
    "df = pd.DataFrame({\n",
    "'语文':[80, 90, None, 70],\n",
    "'数学':[60, 75, 88, 92],\n",
    "'英语':[55, np.nan, np.nan, 90]\n",
    "})\n",
    "# 检测缺失值：True=缺失，False=正常\n",
    "print(\"缺失值位置标记：\")\n",
    "print(pd.isnull(df))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "5c247ee7",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "      语文     数学     英语\n",
      "0  False  False  False\n",
      "1  False  False   True\n",
      "2   True  False   True\n",
      "3  False  False  False\n",
      "语文    25.0\n",
      "数学     0.0\n",
      "英语    50.0\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "#任务3.0  打地基代码\n",
    "import pandas as pd\n",
    "import numpy as np\n",
    "df = pd.DataFrame(\n",
    "{'语文':[80,90,None,70],\n",
    " '数学':[60,75,88,92],\n",
    " '英语':[55,np.NaN,np.NaN,90]\n",
    "})\n",
    "##3.1 缺失值显示\n",
    "print(pd.isnull(df))\n",
    "##3.2 计算缺失值占比\n",
    "##先手算缺失值占比为多少？\n",
    "### 3/12*100%=25%.\n",
    "print(df.isnull().sum()/len(df)*100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "e0b0c638",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     语文  数学    英语\n",
      "0  80.0  60  55.0\n",
      "3  70.0  92  90.0\n"
     ]
    }
   ],
   "source": [
    "## 删除缺失值行\n",
    "print(df.dropna())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "14c25bd5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "     语文  数学    英语\n",
      "0  80.0  60  55.0\n",
      "1  90.0  75   NaN\n",
      "2   NaN  88   NaN\n",
      "3  70.0  92  90.0\n",
      "     语文  数学    英语\n",
      "0  80.0  60  55.0\n",
      "1  90.0  75  66.0\n",
      "2  66.0  88  66.0\n",
      "3  70.0  92  90.0\n",
      "     语文  数学    英语\n",
      "0  80.0  60  55.0\n",
      "1  90.0  75  72.5\n",
      "2  80.0  88  72.5\n",
      "3  70.0  92  90.0\n",
      "     语文  数学    英语\n",
      "0  80.0  60  55.0\n",
      "1  90.0  75  90.0\n",
      "2  90.0  88  90.0\n",
      "3  70.0  92  90.0\n"
     ]
    }
   ],
   "source": [
    "#填充缺失值\n",
    "print(df)\n",
    "## 固定为66数字填充\n",
    "print(df.fillna(66))\n",
    "## 列平均值填充\n",
    "print(df.fillna(df.mean()).round(1))\n",
    "## 思考：用列最大值怎么填充？\n",
    "print(df.fillna(df.max()))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e0672da1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    False\n",
      "1    False\n",
      "2    False\n",
      "3    False\n",
      "4     True\n",
      "dtype: bool\n"
     ]
    }
   ],
   "source": [
    "\n",
    "import pandas as pd\n",
    "# 学生信息表\n",
    "df = pd.DataFrame({\n",
    "'姓名':['张三', '李四', '王五', '赵六', '赵六'],\n",
    "'年龄':[20,21,22,23,23],\n",
    "'班级':['1班','1班','2班','2班','2班']\n",
    "})\n",
    "## 重复值\n",
    "print(df.duplicated())"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "34f4beb5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   姓名  年龄  班级\n",
      "0  张三  20  1班\n",
      "1  李四  21  1班\n",
      "2  王五  22  2班\n",
      "3  赵六  23  2班\n"
     ]
    }
   ],
   "source": [
    "##删除重复行\n",
    "print(df.drop_duplicates(ignore_index=True))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9174ebd4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "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.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
