20230220
This commit is contained in:
1 parent
af381a716e
commit
d5042646a5
1 file changed
+71
-2
+71
-2
@@ -487,10 +487,79 @@
|
||||
"wb.save(filename) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "e17b1435-2b31-421f-8755-c11f0a4ac5c9",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 北海体检情况汇总"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 6,
|
||||
"id": "26343c71-535f-445b-9274-6492febfd435",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2023-02-20T07:11:15.182317Z",
|
||||
"iopub.status.busy": "2023-02-20T07:11:15.181785Z",
|
||||
"iopub.status.idle": "2023-02-20T07:11:15.425443Z",
|
||||
"shell.execute_reply": "2023-02-20T07:11:15.424341Z",
|
||||
"shell.execute_reply.started": "2023-02-20T07:11:15.182267Z"
|
||||
},
|
||||
"tags": []
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"import json\n",
|
||||
"\n",
|
||||
"wb = openpyxl.load_workbook('data/北海体检报告整理数据.xlsx')\n",
|
||||
"sheet = wb.active\n",
|
||||
"# sheets = wb.sheetnames\n",
|
||||
"dict1 = {}\n",
|
||||
"for n in range(2, sheet.max_row+1):\n",
|
||||
" if sheet.cell(n,2).value is None:\n",
|
||||
" break\n",
|
||||
" else: \n",
|
||||
" code = sheet.cell(n, 2).value\n",
|
||||
" dict1.setdefault(code, {}) \n",
|
||||
" dict1[code]['name'] = sheet.cell(n, 3).value \n",
|
||||
" \n",
|
||||
" dict1[code]['sex'] = sheet.cell(n, 4).value \n",
|
||||
" dict1[code]['age'] = sheet.cell(n, 5).value \n",
|
||||
" dict1[code].setdefault('bz',[]) \n",
|
||||
" dict1[code]['bz'].append(sheet.cell(n, 6).value) \n",
|
||||
" \n",
|
||||
"#filename = 'data/北海炼化体检人员情况.json'\n",
|
||||
"#with open(filename, 'w') as fl:\n",
|
||||
"# json.dump(dict1, fl, ensure_ascii=False)\n",
|
||||
"#print('ok')\n",
|
||||
"list1 = []\n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" list2 = []\n",
|
||||
" mbz = set(v['bz'])\n",
|
||||
" list2.append(k)\n",
|
||||
" list2.append(v['name'])\n",
|
||||
" list2.append(v['sex'])\n",
|
||||
" list2.append(v['age'])\n",
|
||||
" list2.append(','.join(mbz))\n",
|
||||
" list1.append(list2)\n",
|
||||
"title = ['体检编号','姓名','性别','年龄','体检症状']\n",
|
||||
"filename = 'data/北海体检报告人员病症统计表.xlsx'\n",
|
||||
"wb = openpyxl.Workbook()\n",
|
||||
"sheet = wb.active\n",
|
||||
"sheet.append(title)\n",
|
||||
"for row in list1:\n",
|
||||
" sheet.append(row)\n",
|
||||
" \n",
|
||||
"wb.save(filename) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "70de1be8-e55c-4b7a-bad9-78ad77f199d0",
|
||||
"id": "f80114cb-d6d1-4c82-ad22-dcd2d5d03b94",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
@@ -498,7 +567,7 @@
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"display_name": "Python 3",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user