{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "d99d999d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "955684bc",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_excel(\"./学生信息.xls\", usecols=['学号', '姓名', '性别', '年级','班级'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "7a49db1c",
   "metadata": {},
   "outputs": [],
   "source": [
    "class_count = df.groupby(['年级', '班级']).size().reset_index(name='人数')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "3e00f787",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>年级</th>\n",
       "      <th>班级</th>\n",
       "      <th>人数</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>26学部</td>\n",
       "      <td>1班</td>\n",
       "      <td>42</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>26学部</td>\n",
       "      <td>2班</td>\n",
       "      <td>41</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>26学部</td>\n",
       "      <td>3班</td>\n",
       "      <td>38</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>26学部</td>\n",
       "      <td>4班</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>26学部</td>\n",
       "      <td>5班</td>\n",
       "      <td>39</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>27学部</td>\n",
       "      <td>1班</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>27学部</td>\n",
       "      <td>2班</td>\n",
       "      <td>47</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>27学部</td>\n",
       "      <td>3班</td>\n",
       "      <td>46</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>27学部</td>\n",
       "      <td>4班</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>27学部</td>\n",
       "      <td>5班</td>\n",
       "      <td>48</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>28学部</td>\n",
       "      <td>1班</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>28学部</td>\n",
       "      <td>2班</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>28学部</td>\n",
       "      <td>3班</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>28学部</td>\n",
       "      <td>4班</td>\n",
       "      <td>49</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      年级  班级  人数\n",
       "0   26学部  1班  42\n",
       "1   26学部  2班  41\n",
       "2   26学部  3班  38\n",
       "3   26学部  4班  40\n",
       "4   26学部  5班  39\n",
       "5   27学部  1班  48\n",
       "6   27学部  2班  47\n",
       "7   27学部  3班  46\n",
       "8   27学部  4班  48\n",
       "9   27学部  5班  48\n",
       "10  28学部  1班  49\n",
       "11  28学部  2班  49\n",
       "12  28学部  3班  49\n",
       "13  28学部  4班  49"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "class_count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bc5324c0",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "6a622610",
   "metadata": {},
   "outputs": [],
   "source": [
    "df = pd.read_excel(\"./学生信息.xls\", usecols=['学号', '姓名', '性别', '年级'])\n",
    "row_strings = set()\n",
    "for _, row in df.iterrows():\n",
    "    row_str = f\"{row['学号']}{row['姓名']}{row['性别']}{row['年级']}\"\n",
    "    row_strings.add(row_str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "c2b0ab79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(633, 4)"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e5f90213",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "633"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(row_strings)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "0ec9fe0a",
   "metadata": {},
   "outputs": [],
   "source": [
    "df1 = pd.read_excel(\"./学生信息2.xls\", usecols=['学号', '姓名', '性别', '年级'])\n",
    "row_strings1 = set()\n",
    "for _, row in df.iterrows():\n",
    "    row_str = f\"{row['学号']}{row['姓名']}{row['性别']}{row['年级']}\"\n",
    "    row_strings1.add(row_str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "75d2483a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'260434于铭达男26学部'"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "row_strings1.pop()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "e5180f79",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'260434于铭达男26学部'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "row_strings  - row_strings1 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e87426b4",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "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.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
