This commit is contained in:
512song committed 2021-11-01 10:17:03 +08:00
1 parent 8b780a6e66
commit b208898522
1 file changed
+109 -19
+109 -19
View File
@@ -55,8 +55,7 @@
" mycol.insert_one(dict1)\n",
" print('ok!')\n",
"else:\n",
" print('该单位已存在!') \n",
" "
" print('该单位已存在!')"
]
},
{
@@ -693,7 +692,7 @@
"import os,sys\n",
"import pymongo\n",
"from gridfs import GridFS\n",
"from bson.objectid import ObjectId\n",
"\n",
"\n",
"myclient = pymongo.MongoClient('mongodb://localhost:27017/')\n",
"mydb = myclient[\"tice\"]\n",
@@ -704,7 +703,6 @@
"x = mycol.find_one(myquery,{s:1})\n",
"if x:\n",
" print(x['report'][sn])\n",
" \n",
"else:\n",
" print('no record!')\n",
"#print(type(x))"
@@ -752,15 +750,15 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 2,
"id": "9e33d1bc-1b71-47f7-928a-16ec435449d6",
"metadata": {
"execution": {
"iopub.execute_input": "2021-10-26T08:21:04.983764Z",
"iopub.status.busy": "2021-10-26T08:21:04.982673Z",
"iopub.status.idle": "2021-10-26T08:21:09.421348Z",
"shell.execute_reply": "2021-10-26T08:21:09.419179Z",
"shell.execute_reply.started": "2021-10-26T08:21:04.983506Z"
"iopub.execute_input": "2021-11-01T01:09:32.605273Z",
"iopub.status.busy": "2021-11-01T01:09:32.604346Z",
"iopub.status.idle": "2021-11-01T01:09:32.942228Z",
"shell.execute_reply": "2021-11-01T01:09:32.940432Z",
"shell.execute_reply.started": "2021-11-01T01:09:32.605167Z"
},
"tags": []
},
@@ -815,15 +813,15 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 13,
"id": "2475a1c3-c2e7-45d6-9685-32e28e606df5",
"metadata": {
"execution": {
"iopub.execute_input": "2021-10-26T13:02:51.590980Z",
"iopub.status.busy": "2021-10-26T13:02:51.590050Z",
"iopub.status.idle": "2021-10-26T13:02:52.262203Z",
"shell.execute_reply": "2021-10-26T13:02:52.260218Z",
"shell.execute_reply.started": "2021-10-26T13:02:51.590874Z"
"iopub.execute_input": "2021-11-01T02:03:59.201350Z",
"iopub.status.busy": "2021-11-01T02:03:59.200377Z",
"iopub.status.idle": "2021-11-01T02:04:00.932234Z",
"shell.execute_reply": "2021-11-01T02:04:00.930325Z",
"shell.execute_reply.started": "2021-11-01T02:03:59.201245Z"
},
"tags": []
},
@@ -842,7 +840,7 @@
"\n",
"wb = openpyxl.load_workbook('file/北海炼化公司职工心理健康量表统计.xlsx')\n",
"sheet = wb.active\n",
"#sheets = wb.sheetnames\n",
"\n",
"dict1 = {}\n",
"for n in range(2,sheet.max_row+1):\n",
" mdm = sheet.cell(n,1).value\n",
@@ -851,8 +849,8 @@
" list1 = [1,2,3,4,5,None]\n",
" for i in range(2,42):\n",
" #if sheet.cell(n,i).value not in list1:\n",
" dict2[i-1] = sheet.cell(n,i).value\n",
" # print(f'error!{mdm}--{sheet.cell(n,i).value}')\n",
" dict2[i-1] = sheet.cell(n,i).value\n",
" dict1[mdm] = dict2\n",
"filename = '北海炼化公司职工心理健康量表统计.json'\n",
"with open(filename,'w') as fl:\n",
@@ -860,10 +858,102 @@
"print('ok')"
]
},
{
"cell_type": "markdown",
"id": "f400d470-d51e-4226-a1c4-54ac711c7f38",
"metadata": {},
"source": [
"## 查询心理健康量表编号重复"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "61887c54-66be-4158-9721-7a995daf1745",
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-01T02:03:47.177819Z",
"iopub.status.busy": "2021-11-01T02:03:47.176858Z",
"iopub.status.idle": "2021-11-01T02:03:48.719338Z",
"shell.execute_reply": "2021-11-01T02:03:48.717050Z",
"shell.execute_reply.started": "2021-11-01T02:03:47.177713Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"355-479已存在!\n",
"401-379已存在!\n",
"493-765已存在!\n"
]
}
],
"source": [
"import openpyxl\n",
"\n",
"wb = openpyxl.load_workbook('file/北海炼化公司职工心理健康量表统计.xlsx')\n",
"sheet = wb.active\n",
"list1 = []\n",
"dict1 = {}\n",
"i = 0\n",
"for n in range(2,sheet.max_row+1):\n",
" mdm = sheet.cell(n,1).value\n",
" if mdm in list1:\n",
" print(F'{i}-{mdm}已存在!')\n",
" else:\n",
" list1.append(mdm)\n",
" i = i + 1\n",
" "
]
},
{
"cell_type": "markdown",
"id": "641cc9a9-45b2-4b81-953c-75d3a27e35d5",
"metadata": {},
"source": [
"## 统计导入JSON文件记录数"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "499a41ef-1b1f-4973-b733-8c322ac1ce09",
"metadata": {
"execution": {
"iopub.execute_input": "2021-11-01T02:03:52.339731Z",
"iopub.status.busy": "2021-11-01T02:03:52.339110Z",
"iopub.status.idle": "2021-11-01T02:03:52.366118Z",
"shell.execute_reply": "2021-11-01T02:03:52.364000Z",
"shell.execute_reply.started": "2021-11-01T02:03:52.339665Z"
},
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"538\n"
]
}
],
"source": [
"import json\n",
"filename = '北海炼化公司职工心理健康量表统计.json'\n",
"item = {}\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"print(len(dict1))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "671d6afe-5ed2-404e-bd8c-df3118ea3743",
"id": "8ddd87ea-75f9-4296-8334-c28e6359fedd",
"metadata": {},
"outputs": [],
"source": []