This commit is contained in:
512song committed 2023-11-14 10:49:31 +00:00
1 parent bec78cd290
commit 2185fd37aa
2 files changed
+338 -41

No files matched your search

+110 -17
View File
@@ -650,7 +650,6 @@
"cell_type": "markdown",
"id": "1ab2aa22-5cc2-4f53-a28d-b30b1ecab15f",
"metadata": {
"jp-MarkdownHeadingCollapsed": true,
"tags": []
},
"source": [
@@ -1109,15 +1108,15 @@
},
{
"cell_type": "code",
"execution_count": 104,
"execution_count": 106,
"id": "0bafbf66-c909-413e-a9c1-c1a5f9c22953",
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-08T01:55:15.141433Z",
"iopub.status.busy": "2023-11-08T01:55:15.141150Z",
"iopub.status.idle": "2023-11-08T01:55:15.238893Z",
"shell.execute_reply": "2023-11-08T01:55:15.238339Z",
"shell.execute_reply.started": "2023-11-08T01:55:15.141408Z"
"iopub.execute_input": "2023-11-14T05:55:33.805333Z",
"iopub.status.busy": "2023-11-14T05:55:33.804539Z",
"iopub.status.idle": "2023-11-14T05:55:33.957265Z",
"shell.execute_reply": "2023-11-14T05:55:33.956626Z",
"shell.execute_reply.started": "2023-11-14T05:55:33.805258Z"
},
"tags": []
},
@@ -1220,15 +1219,15 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 107,
"id": "1aa45b35-7376-4c50-8275-79b090a6c758",
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-11T02:58:46.399097Z",
"iopub.status.busy": "2023-11-11T02:58:46.398632Z",
"iopub.status.idle": "2023-11-11T02:58:46.503284Z",
"shell.execute_reply": "2023-11-11T02:58:46.502753Z",
"shell.execute_reply.started": "2023-11-11T02:58:46.399061Z"
"iopub.execute_input": "2023-11-14T06:00:16.626017Z",
"iopub.status.busy": "2023-11-14T06:00:16.625735Z",
"iopub.status.idle": "2023-11-14T06:00:16.685336Z",
"shell.execute_reply": "2023-11-14T06:00:16.684762Z",
"shell.execute_reply.started": "2023-11-14T06:00:16.625993Z"
},
"tags": []
},
@@ -1237,8 +1236,8 @@
"name": "stdout",
"output_type": "stream",
"text": [
"607\n",
"607\n"
"697\n",
"697\n"
]
}
],
@@ -1261,7 +1260,7 @@
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"filename = 'data/places_result_20231111.csv'\n",
"filename = 'data/places_result_20231114.csv'\n",
"with open(filename,'r',newline='') as csv_file:\n",
" fl = csv.reader(csv_file,delimiter=',')\n",
" header = next(fl) \n",
@@ -1344,10 +1343,104 @@
"wb.save(filename)"
]
},
{
"cell_type": "markdown",
"id": "c410f403-5c93-4a03-a06b-900ecd08a1b4",
"metadata": {},
"source": [
"## 导入问卷信息"
]
},
{
"cell_type": "code",
"execution_count": 113,
"id": "63d5bccf-7351-4a08-863d-b1ca3b263eca",
"metadata": {
"execution": {
"iopub.execute_input": "2023-11-14T06:14:23.732763Z",
"iopub.status.busy": "2023-11-14T06:14:23.732454Z",
"iopub.status.idle": "2023-11-14T06:14:23.789472Z",
"shell.execute_reply": "2023-11-14T06:14:23.788550Z",
"shell.execute_reply.started": "2023-11-14T06:14:23.732734Z"
},
"tags": []
},
"outputs": [
{
"ename": "ValueError",
"evalue": "invalid literal for int() with base 10: 'ender'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[113], line 38\u001b[0m\n\u001b[1;32m 36\u001b[0m list2\u001b[38;5;241m.\u001b[39mappend(\u001b[38;5;241m0\u001b[39m)\n\u001b[1;32m 37\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m k, v \u001b[38;5;129;01min\u001b[39;00m content\u001b[38;5;241m.\u001b[39mitems():\n\u001b[0;32m---> 38\u001b[0m i \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mint\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mk\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m:\u001b[49m\u001b[43m]\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 39\u001b[0m list2[i\u001b[38;5;241m-\u001b[39m\u001b[38;5;241m1\u001b[39m] \u001b[38;5;241m=\u001b[39m v\n\u001b[1;32m 40\u001b[0m dict2[item[\u001b[38;5;241m2\u001b[39m]] \u001b[38;5;241m=\u001b[39m list2\n",
"\u001b[0;31mValueError\u001b[0m: invalid literal for int() with base 10: 'ender'"
]
}
],
"source": [
"import json\n",
"import csv\n",
"import openpyxl\n",
"import time\n",
"from datetime import date\n",
"\n",
"filename = 'data/result_北海炼化2023.json'\n",
"with open(filename,'r') as fl:\n",
" dict1 = json.load(fl) \n",
"\n",
"filename = 'data/北海炼化2023年.json'\n",
"with open(filename,'r') as fl:\n",
" dict3 = json.load(fl)\n",
"\n",
"phone = set()\n",
"phone1 = set()\n",
"for k,v in dict3.items():\n",
" if 'phone' in v.keys():\n",
" phone.add(v['phone'])\n",
"list1 = []\n",
"filename = 'data/Survey_20231114.csv'\n",
"with open(filename,'r',newline='') as csv_file:\n",
" fl = csv.reader(csv_file,delimiter=',')\n",
" header = next(fl) \n",
" for line in fl:\n",
" #line = re.sub('[\\r\\n\\f ]{1,}', '', line)\n",
" list1.append(line)\n",
"dict2 = {}\n",
"m_rq = '2023-11-14'\n",
"rq= date.fromisoformat(m_rq.replace('/','-'))\n",
"for item in list1:\n",
" if item[2] in phone: \n",
" content = json.loads(item[5])\n",
" list2 = []\n",
" for i in range(0,60):\n",
" list2.append(0)\n",
" for k, v in content.items():\n",
" i = int(k[1:])\n",
" list2[i-1] = v\n",
" dict2[item[2]] = list2\n",
"print(dict2) \n",
"for k, v in dict3.items():\n",
" if 'phone' in v.keys() and v['phone'] in dict2.keys():\n",
" if k not in dict1.keys():\n",
" dict1.setdefault(k,{})\n",
" dict1[k] = dict3[k]\n",
" days = (rq-birth).days \n",
" dict1[k]['age'] = int(days/365)\n",
" dict1[k]['month'] = int(days/365*12)\n",
" \n",
" dict1[k]['tcm'] = dict2[str(v['phone'])]\n",
" \n",
"filename = 'data/result_北海炼化new.json'\n",
"\n",
"with open(filename,'w') as fl:\n",
" json.dump(dict1, fl, ensure_ascii=False) "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7111dc19-387c-4e4d-bfed-0273cf0809fb",
"id": "c0128f52-8697-4258-aba0-89a522fb9cc0",
"metadata": {},
"outputs": [],
"source": []