This commit is contained in:
512song committed 2021-11-25 08:18:36 +08:00
1 parent 1b88f510c6
commit 265dbb8d66
2 files changed
+217 -12

No files matched your search

+215 -10
View File
@@ -98,15 +98,8 @@
},
{
"cell_type": "code",
"execution_count": 60,
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-16T13:34:52.373277Z",
"iopub.status.busy": "2021-11-16T13:34:52.372041Z",
"iopub.status.idle": "2021-11-16T13:34:52.529747Z",
"shell.execute_reply": "2021-11-16T13:34:52.527803Z",
"shell.execute_reply.started": "2021-11-16T13:34:52.373167Z"
},
"tags": []
},
"outputs": [],
@@ -174,6 +167,218 @@
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 穴位数据导入"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import re\n",
"dict1 = {}\n",
"filename = 'file/zhongyi/xuewei.json'\n",
"with open(filename,'r',encoding='utf-8') as fl:\n",
" for line in fl:\n",
" line1 = json.loads(re.sub(r'\\xa0','',line))\n",
" list1 = line1['tables']\n",
" list2 = line1['contents']\n",
" dict2 = dict(zip(list1, list2))\n",
" #print(line1['title'],dict1)\n",
" #print(dict1.keys())\n",
" #print(line1)\n",
" dict1.setdefault(line1['title'][0],{})\n",
" dict1[line1['title'][0]]['简介'] = line1['jj'] \n",
" dict1[line1['title'][0]]['内容'] = dict2\n",
"filename = './file/穴位.json'\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict1, fl) "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 穴位数据导出Excel表"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-24T03:41:43.078279Z",
"iopub.status.busy": "2021-11-24T03:41:43.077279Z",
"iopub.status.idle": "2021-11-24T03:41:43.162298Z",
"shell.execute_reply": "2021-11-24T03:41:43.161298Z",
"shell.execute_reply.started": "2021-11-24T03:41:43.078279Z"
},
"tags": []
},
"outputs": [
{
"ename": "IndexError",
"evalue": "list index out of range",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)",
"\u001b[1;32m~\\AppData\\Local\\Temp/ipykernel_166520/2691368177.py\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m 23\u001b[0m \u001b[0msheet\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34mf'E{i}'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mv\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'简介'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m3\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m':'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 24\u001b[0m \u001b[0msheet\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34mf'F{i}'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mv\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'简介'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m4\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m':'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 25\u001b[1;33m \u001b[0msheet\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34mf'G{i}'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mv\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'简介'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msplit\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m':'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 26\u001b[0m \u001b[0mi\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 27\u001b[0m \u001b[0mwb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msave\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilename\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
"\u001b[1;31mIndexError\u001b[0m: list index out of range"
]
}
],
"source": [
"import json\n",
"import openpyxl\n",
"\n",
"filename = 'file/穴位.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl)\n",
"filename = 'file/穴位简要情况表.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"sheet['A1'] = '穴位名称'\n",
"sheet['B1'] = '隶属'\n",
"sheet['C1'] = '位置'\n",
"sheet['D1'] = '主治'\n",
"sheet['E1'] = '功能'\n",
"sheet['F1'] = '操作'\n",
"sheet['G1'] = '主要配伍'\n",
"i = 2\n",
"for k, v in dict1.items():\n",
" sheet[f'A{i}'] = k\n",
" sheet[f'B{i}'] = v['简介'][0].split(':')[1]\n",
" sheet[f'C{i}'] = v['简介'][1].split(':')[1]\n",
" sheet[f'D{i}'] = v['简介'][2].split(':')[1]\n",
" sheet[f'E{i}'] = v['简介'][3].split(':')[1]\n",
" sheet[f'F{i}'] = v['简介'][4].split(':')[1]\n",
" sheet[f'G{i}'] = v['简介'][5].split(':')[1] \n",
" i += 1\n",
"wb.save(filename) \n",
"print('ok!')\n",
"\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 北海炼化体检数据提取"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-24T03:23:57.451845Z",
"iopub.status.busy": "2021-11-24T03:23:57.451845Z",
"iopub.status.idle": "2021-11-24T03:23:57.624934Z",
"shell.execute_reply": "2021-11-24T03:23:57.624934Z",
"shell.execute_reply.started": "2021-11-24T03:23:57.451845Z"
},
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import openpyxl\n",
"import os,sys,shutil\n",
"\n",
"file_name = 'file/中石化北海炼化2020年团体体检报告.xlsx'\n",
"wb = openpyxl.load_workbook(file_name)\n",
"sheet = wb.active\n",
"dict1 = {}\n",
"for n in range(1,sheet.max_row+1):\n",
" bh = sheet.cell(n,2).value\n",
" name = sheet.cell(n,3).value\n",
" xb = sheet.cell(n,4).value\n",
" nl = sheet.cell(n,5).value\n",
" bz = sheet.cell(n,7).value\n",
" dict1.setdefault(bh,{})\n",
" dict1[bh]['姓名'] = name\n",
" dict1[bh]['性别'] = xb\n",
" dict1[bh]['年龄'] = nl\n",
" dict1[bh].setdefault('病症',[])\n",
" dict1[bh]['病症'].append(bz.strip())\n",
"wb.close()\n",
"#print(dict1)\n",
" \n",
" \n",
"filename = 'file/中石化北海炼化2020年体检人员情况表.xlsx'\n",
"wb = openpyxl.Workbook()\n",
"sheet = wb.active\n",
"sheet['A1'] = '体检编号'\n",
"sheet['B1'] = '姓名'\n",
"sheet['C1'] = '性别'\n",
"sheet['D1'] = '年龄'\n",
"sheet['E1'] = '异常名称'\n",
"\n",
"i =2\n",
"for k, v in dict1.items():\n",
" sheet[f'A{i}'] = k\n",
" sheet[f'B{i}'] = v['姓名']\n",
" sheet[f'C{i}'] = v['性别']\n",
" sheet[f'D{i}'] = v['年龄']\n",
" sheet[f'E{i}'] = ','.join(v['病症']) \n",
" i += 1\n",
"\n",
"wb.save(filename) \n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import openpyxl\n",
"import json\n",
"import pymongo\n",
"\n",
"myclient = pymongo.MongoClient('mongodb://512song:songyi@192.168.3.100:27017/tice')\n",
"#dblist = myclient.list_database_names()\n",
"mydb = myclient['tice']\n",
" \n",
"collist = mydb. list_collection_names()\n",
"print(collist)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import json\n",
"import pymongo\n",
"\n",
"myclient = pymongo.MongoClient('mongodb://192.168.3.100:27017/')\n",
"#dblist = myclient.list_database_names()\n",
"mydb = myclient['tice']\n",
" \n",
"collist = mydb. list_collection_names()\n",
"print(collist)"
]
},
{
"cell_type": "code",
"execution_count": null,
@@ -184,7 +389,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -198,7 +403,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.9.1"
}
},
"nbformat": 4,
+2 -2
View File
@@ -607,7 +607,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
@@ -621,7 +621,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.9.1"
}
},
"nbformat": 4,