20240804
This commit is contained in:
1 parent
ae270581b1
commit
11a1e51802
5 files changed
+3127
-3045
No files matched your search
+95
-2
@@ -476,7 +476,7 @@
|
||||
"import csv\n",
|
||||
"\n",
|
||||
"list1 = []\n",
|
||||
"filename = 'data/Survey_20231027.csv'\n",
|
||||
"filename = 'data/Survey_20240801.csv'\n",
|
||||
"with open(filename,'r',newline='') as csv_file:\n",
|
||||
" fl = csv.reader(csv_file,delimiter=',')\n",
|
||||
" header = next(fl) \n",
|
||||
@@ -504,6 +504,99 @@
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"id": "a51a346c-8a3a-425c-be76-940f11c2e1ab",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-08-03T14:02:17.514754Z",
|
||||
"iopub.status.busy": "2024-08-03T14:02:17.514034Z",
|
||||
"iopub.status.idle": "2024-08-03T14:02:17.581525Z",
|
||||
"shell.execute_reply": "2024-08-03T14:02:17.580974Z",
|
||||
"shell.execute_reply.started": "2024-08-03T14:02:17.514688Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"38\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import datetime\n",
|
||||
"import csv\n",
|
||||
"\n",
|
||||
"list1 = []\n",
|
||||
"filename = 'data/Survey_20240801.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",
|
||||
"#print(list1)\n",
|
||||
"list3 = []\n",
|
||||
"dict1 = {}\n",
|
||||
"bh = 1\n",
|
||||
"for item in list1:\n",
|
||||
" phone = item[2]\n",
|
||||
" content = json.loads(item[5])\n",
|
||||
" name = content['name']\n",
|
||||
" sex = content['Gender']\n",
|
||||
" age = content['Age']\n",
|
||||
" del content['name']\n",
|
||||
" del content['Gender']\n",
|
||||
" del content['Age']\n",
|
||||
" for k, v in content.items():\n",
|
||||
" if 'O' in k:\n",
|
||||
" psy =[]\n",
|
||||
" for i in range(1,31):\n",
|
||||
" m_key = 'q'+str(i)+'O'\n",
|
||||
" psy.append(content[m_key])\n",
|
||||
" elif 'M' in k:\n",
|
||||
" psy =[]\n",
|
||||
" for i in range(1,48):\n",
|
||||
" m_key = 'q'+str(i)+'M'\n",
|
||||
" psy.append(content[m_key])\n",
|
||||
" elif 'qv' in k:\n",
|
||||
" spine =[]\n",
|
||||
" for i in range(1,27):\n",
|
||||
" m_key = 'qv'+str(i)\n",
|
||||
" if m_key in content.keys():\n",
|
||||
" spine.append(content[m_key])\n",
|
||||
" else:\n",
|
||||
" spine.append(0)\n",
|
||||
" \n",
|
||||
" else:\n",
|
||||
" tcm = []\n",
|
||||
" for i in range(1,61):\n",
|
||||
" m_key = 'q'+str(i)\n",
|
||||
" if m_key in content.keys():\n",
|
||||
" tcm.append(content[m_key])\n",
|
||||
" else:\n",
|
||||
" tcm.append(0)\n",
|
||||
" dict1.setdefault(bh,{})\n",
|
||||
" #print(spine)\n",
|
||||
" dict1[bh]['name'] = name\n",
|
||||
" dict1[bh]['sex'] = sex\n",
|
||||
" dict1[bh]['age'] = age\n",
|
||||
" dict1[bh]['psy'] = psy\n",
|
||||
" dict1[bh]['tcm'] = tcm\n",
|
||||
" dict1[bh]['spine'] = spine\n",
|
||||
" bh += 1 \n",
|
||||
" #list3.append(list2)\n",
|
||||
"filename = 'data/积家基础数据240801.json'\n",
|
||||
"\n",
|
||||
"with open(filename,'w') as fl:\n",
|
||||
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
||||
"print(len(dict1))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5ab7d644-c90a-4877-9abf-6d4bd88ef3ef",
|
||||
@@ -805,7 +898,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.12"
|
||||
"version": "3.12.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
+53
-1
@@ -1631,8 +1631,60 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"execution_count": 113,
|
||||
"id": "5aefec37-8db4-49c0-bb73-56906f3510ec",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-07-25T15:31:51.204580Z",
|
||||
"iopub.status.busy": "2024-07-25T15:31:51.203825Z",
|
||||
"iopub.status.idle": "2024-07-25T15:31:51.226327Z",
|
||||
"shell.execute_reply": "2024-07-25T15:31:51.225747Z",
|
||||
"shell.execute_reply.started": "2024-07-25T15:31:51.204509Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import openpyxl\n",
|
||||
"\n",
|
||||
"filename = 'data/result_青海all_2.json'\n",
|
||||
"list4 = ['颈椎','胸椎','腰椎','骶尾椎']\n",
|
||||
"list5 = [[0,10,10],[10,17,7],[17,24,6],[24,26,2]]\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl) \n",
|
||||
"data_list = []\n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" \n",
|
||||
" if 'spine' in v.keys():\n",
|
||||
" list6 = []\n",
|
||||
" list6.append(str(k).rjust(4,'0'))\n",
|
||||
" list6.append(v['name'])\n",
|
||||
" list6.append(v['sex'])\n",
|
||||
" list6.append(v['unit'])\n",
|
||||
" list6.append(v['age']) \n",
|
||||
" spine = v['spine']\n",
|
||||
" for i in range(0,4):\n",
|
||||
" score = 0\n",
|
||||
" for ii in range(list5[i][0],list5[i][1]):\n",
|
||||
" score+= spine[ii]\n",
|
||||
" list6.append(int(score/list5[i][2]*100)-100)\n",
|
||||
" for item in spine:\n",
|
||||
" list6.append(item)\n",
|
||||
" data_list.append(list6)\n",
|
||||
" \n",
|
||||
"filename = 'data/青海脊椎情况表.xlsx'\n",
|
||||
"wb = openpyxl.Workbook()\n",
|
||||
"sheet = wb.active\n",
|
||||
"#sheet.append(title)\n",
|
||||
"for row in data_list:\n",
|
||||
" sheet.append(row)\n",
|
||||
" \n",
|
||||
"wb.save(filename) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "df0dc1d9-ad92-44b5-9214-14d433a877f1",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
|
||||
+18
-2824
File diff suppressed because it is too large.
Load diff
+1714
-157
File diff suppressed because it is too large.
Load diff
+1247
-61
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user