{ "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": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
年级班级人数
026学部1班42
126学部2班41
226学部3班38
326学部4班40
426学部5班39
527学部1班48
627学部2班47
727学部3班46
827学部4班48
927学部5班48
1028学部1班49
1128学部2班49
1228学部3班49
1328学部4班49
\n", "
" ], "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 }