20251117
This commit is contained in:
1 parent
48f119d087
commit
31ddcb887f
9 files changed
+1089
-276
No files matched your search
+381
-74
@@ -975,26 +975,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"execution_count": null,
|
||||
"id": "396e64b8-c306-4613-9848-f0f183052b78",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2025-10-10T02:18:51.157197Z",
|
||||
"iopub.status.busy": "2025-10-10T02:18:51.156880Z",
|
||||
"iopub.status.idle": "2025-10-10T02:18:51.211412Z",
|
||||
"shell.execute_reply": "2025-10-10T02:18:51.210755Z",
|
||||
"shell.execute_reply.started": "2025-10-10T02:18:51.157161Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"210 ok\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import csv\n",
|
||||
@@ -1033,26 +1017,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"execution_count": null,
|
||||
"id": "f60e8194-7ef6-49d8-8538-9b79f35bb64d",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2025-10-10T02:09:50.365387Z",
|
||||
"iopub.status.busy": "2025-10-10T02:09:50.364816Z",
|
||||
"iopub.status.idle": "2025-10-10T02:09:50.391653Z",
|
||||
"shell.execute_reply": "2025-10-10T02:09:50.391205Z",
|
||||
"shell.execute_reply.started": "2025-10-10T02:09:50.365335Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"145 ok\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import csv\n",
|
||||
@@ -1117,17 +1085,9 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 28,
|
||||
"execution_count": null,
|
||||
"id": "f0853629-e971-492b-88c8-4e9521b4b017",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2025-10-10T02:16:14.316496Z",
|
||||
"iopub.status.busy": "2025-10-10T02:16:14.315869Z",
|
||||
"iopub.status.idle": "2025-10-10T02:16:14.344471Z",
|
||||
"shell.execute_reply": "2025-10-10T02:16:14.343924Z",
|
||||
"shell.execute_reply.started": "2025-10-10T02:16:14.316435Z"
|
||||
}
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
@@ -1161,17 +1121,324 @@
|
||||
"wb.save(filename)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "98de56de-95fe-4f21-be25-896fb1bda175",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 问卷转换"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"execution_count": null,
|
||||
"id": "22be8f39-afbb-448a-8ae6-c825c7d38757",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import openpyxl\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"title = []\n",
|
||||
"\n",
|
||||
"filename = 'data/surveys_records_宁夏能化.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"list1 = []\n",
|
||||
"title = ['id', 'date_created']\n",
|
||||
"data_title = ['name', 'gender', 'birth', 'code', 'unit', 'height', 'weight', 'next_weight', 'waist', 'hip', 'level4', 'level3', 'level2', 'recipe', 'level1', 'last_level4', 'last_level3', 'last_level2', 'last_level1', 'last_recipe', 'last_lose', 'last_sport', 'sport_type', 'sport_duration', 'last_sport_time', 'last_lose-Comment', 'last_recipe-Comment', 'last_lose_weight', 'last_sport-Comment', 'sport_type-Comment']\n",
|
||||
"for item in dict1:\n",
|
||||
" list2 = []\n",
|
||||
" for xm in title:\n",
|
||||
" if xm in item.keys():\n",
|
||||
" list2.append(item[xm])\n",
|
||||
" else:\n",
|
||||
" list2.append('')\n",
|
||||
" for xm in data_title:\n",
|
||||
" if xm in item['data'].keys():\n",
|
||||
" if xm =='sport_type':\n",
|
||||
" list2.append(','.join(item['data'][xm]))\n",
|
||||
" else:\n",
|
||||
" list2.append(item['data'][xm])\n",
|
||||
" else:\n",
|
||||
" list2.append('')\n",
|
||||
" \n",
|
||||
" list1.append(list2)\n",
|
||||
"all_title = ['id', 'date_created','name', 'gender', 'birth', 'code', 'unit', 'height', 'weight', 'next_weight', 'waist', 'hip', 'level4', 'level3', 'level2', 'recipe', 'level1', 'last_level4', 'last_level3', 'last_level2', 'last_level1', 'last_recipe', 'last_lose', 'last_sport', 'sport_type', 'sport_duration', 'last_sport_time', 'last_lose-Comment', 'last_recipe-Comment', 'last_lose_weight', 'last_sport-Comment', 'sport_type-Comment']\n",
|
||||
"filename = 'data/宁夏能化干预人员问卷(20251114).xlsx'\n",
|
||||
"wb = openpyxl.Workbook()\n",
|
||||
"sheet = wb.active\n",
|
||||
"sheet.append(all_title)\n",
|
||||
"for row in list1:\n",
|
||||
" sheet.append(row)\n",
|
||||
" \n",
|
||||
"wb.save(filename) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ad2f24f2-f43c-4181-a5e4-16876b0d7443",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2025-10-10T02:18:10.620552Z",
|
||||
"iopub.status.busy": "2025-10-10T02:18:10.619865Z",
|
||||
"iopub.status.idle": "2025-10-10T02:18:10.652211Z",
|
||||
"shell.execute_reply": "2025-10-10T02:18:10.651710Z",
|
||||
"shell.execute_reply.started": "2025-10-10T02:18:10.620490Z"
|
||||
"iopub.execute_input": "2025-11-14T09:41:32.283676Z",
|
||||
"iopub.status.busy": "2025-11-14T09:41:32.283096Z",
|
||||
"iopub.status.idle": "2025-11-14T09:41:32.303376Z",
|
||||
"shell.execute_reply": "2025-11-14T09:41:32.302637Z",
|
||||
"shell.execute_reply.started": "2025-11-14T09:41:32.283623Z"
|
||||
}
|
||||
},
|
||||
"source": [
|
||||
"## 问卷导入数据库"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "88f6e148-bfd3-4394-8cfd-de7c84306431",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 导入人员信息"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "747ff8ae-9e50-452f-9dcf-f5ba7c5b8f51",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import openpyxl\n",
|
||||
"import psycopg2\n",
|
||||
"\n",
|
||||
"conn = psycopg2.connect(\n",
|
||||
" host=\"localhost\",\n",
|
||||
" database=\"tice\",\n",
|
||||
" user=\"mydata\",\n",
|
||||
" password=\"songyi\"\n",
|
||||
")\n",
|
||||
"cur = conn.cursor()\n",
|
||||
"wb = openpyxl.load_workbook('data/宁夏能化干预人员问卷(20251114).xlsx',data_only=True)\n",
|
||||
"sheet = wb.active\n",
|
||||
"# sheets = wb.sheetnames\n",
|
||||
"person = {}\n",
|
||||
"for n in range(2, sheet.max_row+1):\n",
|
||||
" code = str(sheet.cell(n, 6).value)\n",
|
||||
" person.setdefault(code, {})\n",
|
||||
" dict1 = {}\n",
|
||||
" dict1['name'] = sheet.cell(n, 3).value\n",
|
||||
" dict1['sex'] = sheet.cell(n, 4).value\n",
|
||||
" birth = str(sheet.cell(n, 5).value).split()[0]\n",
|
||||
" if len(birth)==7:\n",
|
||||
" dict1['birth'] = birth+'-01'\n",
|
||||
" else:\n",
|
||||
" dict1['birth'] = birth\n",
|
||||
" dict1['unit'] = sheet.cell(n, 7).value\n",
|
||||
" person[code] = dict1\n",
|
||||
"org_id = 1\n",
|
||||
"data1 = []\n",
|
||||
"for k,v in person.items():\n",
|
||||
" tuple1 = (v['name'],v['sex'],v['unit'],v['birth'],k,org_id)\n",
|
||||
" print(tuple1)\n",
|
||||
" data1.append(tuple1)\n",
|
||||
"sql = \"INSERT INTO fitness_person ( name, sex,unit,birth,code,org_id) VALUES (%s, %s, %s,%s, %s, %s)\" \n",
|
||||
"#print(data1)\n",
|
||||
"cur.executemany(sql, data1)\n",
|
||||
"conn.commit()\n",
|
||||
"\n",
|
||||
"# 关闭连接\n",
|
||||
"cur.close()\n",
|
||||
"conn.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "5c2a37a0-18d3-4c89-8dd9-283a417b5c60",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"### 导入问卷信息"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "0b386dac-a335-41ba-8838-59b2866bb9a3",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import openpyxl\n",
|
||||
"import psycopg2\n",
|
||||
"\n",
|
||||
"conn = psycopg2.connect(\n",
|
||||
" host=\"localhost\",\n",
|
||||
" database=\"tice\",\n",
|
||||
" user=\"mydata\",\n",
|
||||
" password=\"songyi\"\n",
|
||||
")\n",
|
||||
"cur = conn.cursor()\n",
|
||||
"\n",
|
||||
"org_id = 1\n",
|
||||
"event_id = 1\n",
|
||||
"filename = 'data/surveys_records_宁夏能化.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"list1 = []\n",
|
||||
"title = ['date_created', 'height', 'weight', 'next_weight', 'waist', 'hip', 'level4', 'level3', 'level2', 'recipe', 'level1', 'last_level4', 'last_level3', 'last_level2', 'last_level1', 'last_recipe', 'last_lose', 'last_sport', 'sport_type', 'sport_duration', 'last_sport_time', 'last_lose_Comment', 'last_recipe_Comment', 'last_lose_weight', 'last_sport_Comment', 'sport_type_Comment']\n",
|
||||
"data_title = ['height', 'weight', 'next_weight', 'waist', 'hip', 'level4', 'level3', 'level2', 'recipe', 'level1', 'last_level4', 'last_level3', 'last_level2', 'last_level1', 'last_recipe', 'last_lose', 'last_sport', 'sport_type', 'sport_duration', 'last_sport_time', 'last_lose-Comment', 'last_recipe-Comment', 'last_lose_weight', 'last_sport-Comment', 'sport_type-Comment']\n",
|
||||
"for item in dict1:\n",
|
||||
" \n",
|
||||
" code = item['data']['code']\n",
|
||||
" sql = \"SELECT id from fitness_person where code = %s and org_id = %s\"\n",
|
||||
" params = (code,org_id)\n",
|
||||
" cur.execute(sql, params)\n",
|
||||
" rows = cur.fetchone()\n",
|
||||
" if rows:\n",
|
||||
" list2 = []\n",
|
||||
" id = rows[0]\n",
|
||||
" list2.append(event_id)\n",
|
||||
" list2.append(id)\n",
|
||||
" date_created = item['date_created']\n",
|
||||
" list2.append(date_created)\n",
|
||||
" for xm in data_title:\n",
|
||||
" if xm in item['data'].keys():\n",
|
||||
" if xm =='sport_type':\n",
|
||||
" list2.append(','.join(item['data'][xm]))\n",
|
||||
" else:\n",
|
||||
" list2.append(item['data'][xm])\n",
|
||||
" else:\n",
|
||||
" list2.append('')\n",
|
||||
" list1.append(tuple(list2))\n",
|
||||
"sql = \"INSERT INTO fitness_survey_data (event_id,user_id,date_created, height, weight, next_weight, waist, hip, level4, level3, level2, recipe, level1, last_level4, last_level3, last_level2, last_level1, last_recipe, last_lose, last_sport, sport_type, sport_duration, last_sport_time, last_lose_Comment, last_recipe_Comment, last_lose_weight, last_sport_Comment, sport_type_Comment)\" \n",
|
||||
"sql = sql + \" VALUES (%s,%s, %s, %s,%s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s, %s, %s, %s)\"\n",
|
||||
"cur.executemany(sql, list1)\n",
|
||||
"conn.commit()\n",
|
||||
"\n",
|
||||
"# 关闭连接\n",
|
||||
"cur.close()\n",
|
||||
"conn.close()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "83a2518b-12d8-4ef8-8ee9-5b4289a94208",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 问卷导入JSON"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "b7133988-213c-4b52-8d6b-17b56b8ea310",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import openpyxl\n",
|
||||
"\n",
|
||||
"wb = openpyxl.load_workbook('data/宁夏能化干预人员问卷(20251114).xlsx',data_only=True)\n",
|
||||
"sheet = wb.active\n",
|
||||
"# sheets = wb.sheetnames\n",
|
||||
"person = {}\n",
|
||||
"for n in range(2, sheet.max_row+1):\n",
|
||||
" code = str(sheet.cell(n, 6).value)\n",
|
||||
" person.setdefault(code, {})\n",
|
||||
" dict1 = {}\n",
|
||||
" dict1['name'] = sheet.cell(n, 3).value\n",
|
||||
" dict1['sex'] = sheet.cell(n, 4).value\n",
|
||||
" birth = str(sheet.cell(n, 5).value).split()[0]\n",
|
||||
" if len(birth)==7:\n",
|
||||
" dict1['birth'] = birth+'-01'\n",
|
||||
" else:\n",
|
||||
" dict1['birth'] = birth\n",
|
||||
" dict1['unit'] = sheet.cell(n, 7).value\n",
|
||||
" person[code] = dict1\n",
|
||||
"#print(person)\n",
|
||||
"\n",
|
||||
"filename = 'data/surveys_records_宁夏能化.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"list1 = []\n",
|
||||
"title = ['date_created', 'height', 'weight', 'next_weight', 'waist', 'hip', 'level4', 'level3', 'level2', 'recipe', 'level1', 'last_level4', 'last_level3', 'last_level2', 'last_level1', 'last_recipe', 'last_lose', 'last_sport', 'sport_type', 'sport_duration', 'last_sport_time', 'last_lose_Comment', 'last_recipe_Comment', 'last_lose_weight', 'last_sport_Comment', 'sport_type_Comment']\n",
|
||||
"data_title = ['height', 'weight', 'next_weight', 'waist', 'hip', 'level4', 'level3', 'level2', 'recipe', 'level1', 'last_level4', 'last_level3', 'last_level2', 'last_level1', 'last_recipe', 'last_lose', 'last_sport', 'sport_type', 'sport_duration', 'last_sport_time', 'last_lose-Comment', 'last_recipe-Comment', 'last_lose_weight', 'last_sport-Comment', 'sport_type-Comment']\n",
|
||||
"for item in dict1: \n",
|
||||
" dict2 = {}\n",
|
||||
" code = item['data']['code']\n",
|
||||
" rq = item['date_created'].split()[0]\n",
|
||||
" dict2['height'] = item['data']['height']\n",
|
||||
" dict2['weight'] = item['data']['weight']\n",
|
||||
" dict2['next_weight'] = item['data']['weight']-item['data']['next_weight']\n",
|
||||
" dict2['bmi'] = (item['data']['weight']/item['data']['height'])/item['data']['height']*10000\n",
|
||||
" bmi = (item['data']['weight']/item['data']['height'])/item['data']['height']*10000\n",
|
||||
" if bmi<18.5:\n",
|
||||
" bmi_zt = '体重偏轻'\n",
|
||||
" elif bmi >=18.5 and bmi <24.0:\n",
|
||||
" bmi_zt = '体重正常'\n",
|
||||
" elif bmi >=24.0 and bmi <28.0:\n",
|
||||
" bmi_zt = '体重超重'\n",
|
||||
" else:\n",
|
||||
" bmi_zt = '体重肥胖'\n",
|
||||
" dict2['bmi_zt'] = bmi_zt\n",
|
||||
" dict2['waist'] = item['data']['waist']\n",
|
||||
" dict2['hip'] = item['data']['hip']\n",
|
||||
" whr = dict2['waist']/dict2['hip']\n",
|
||||
" if item['data']['gender'] =='male' and whr > 0.9:\n",
|
||||
" whr_zt = '超标'\n",
|
||||
" elif item['data']['gender'] =='female' and whr > 0.85:\n",
|
||||
" whr_zt = '超标'\n",
|
||||
" else:\n",
|
||||
" whr_zt = '正常'\n",
|
||||
" dict2['whr'] = whr\n",
|
||||
" dict2['whr_zt'] = whr_zt\n",
|
||||
" if 'sport_type' in item['data'].keys(): \n",
|
||||
" dict2['sport_type'] = ','.join(item['data']['sport_type']).replace('other','其他')\n",
|
||||
" dict2['sport_duration'] = item['data']['sport_duration']\n",
|
||||
" dict2['recipe'] = item['data']['recipe']\n",
|
||||
" if 'last_sport' in item['data'].keys(): \n",
|
||||
" dict2['last_sport'] = item['data']['last_sport']\n",
|
||||
" if 'last_sport_time' in item['data'].keys():\n",
|
||||
" dict2['last_sport_time'] = item['data']['last_sport_time']\n",
|
||||
" if 'last_sport-Comment' in item['data'].keys():\n",
|
||||
" dict2['last_sport-Comment'] = item['data']['last_sport-Comment']\n",
|
||||
" dict2['last_recipe'] = item['data']['last_recipe']\n",
|
||||
" if 'last_recipe-Comment' in item['data'].keys(): \n",
|
||||
" dict2['last_recipe-Comment'] = item['data']['last_recipe-Comment']\n",
|
||||
" if 'last_lose' in item['data'].keys(): \n",
|
||||
" dict2['last_lose'] = item['data']['last_lose']\n",
|
||||
" if 'last_lose_weight' in item['data'].keys():\n",
|
||||
" dict2['last_lose_weight'] = item['data']['last_lose_weight']\n",
|
||||
" if 'last_lose-Comment' in item['data'].keys(): \n",
|
||||
" dict2['last_lose-Comment'] = item['data']['last_lose-Comment']\n",
|
||||
" if code in person.keys():\n",
|
||||
" person[code][rq] = dict2\n",
|
||||
"filename = 'data/宁夏能化干预人员问卷情况.json'\n",
|
||||
"\n",
|
||||
"with open(filename,'w') as fl:\n",
|
||||
" json.dump(person, fl, ensure_ascii=False)\n",
|
||||
"print(len(person),'ok')\n",
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "7805ebad-fe9d-4bc2-a537-c665fc831332",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 问卷信息汇总导出"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 45,
|
||||
"id": "633c35d3-61f0-4a9d-9982-441e4c1291b9",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2025-11-17T09:35:16.409939Z",
|
||||
"iopub.status.busy": "2025-11-17T09:35:16.409246Z",
|
||||
"iopub.status.idle": "2025-11-17T09:35:16.664860Z",
|
||||
"shell.execute_reply": "2025-11-17T09:35:16.664302Z",
|
||||
"shell.execute_reply.started": "2025-11-17T09:35:16.409918Z"
|
||||
}
|
||||
},
|
||||
"outputs": [],
|
||||
@@ -1179,38 +1446,78 @@
|
||||
"import json\n",
|
||||
"import openpyxl\n",
|
||||
"\n",
|
||||
"\n",
|
||||
"title = ['员工编号','姓名','性别','部门','手机号码']\n",
|
||||
"\n",
|
||||
"filename = 'data/survey_宁夏能化干预人员.json'\n",
|
||||
"filename = 'data/宁夏能化干预人员问卷情况.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"\n",
|
||||
"filename = 'data/宁夏能化干预人员.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict2 = json.load(fl)\n",
|
||||
"list1 = ['name','sex','birth','unit']\n",
|
||||
"xm = ['height','weight','next_weight','bmi','bmi_zt','waist', 'hip','whr','whr_zt' ]\n",
|
||||
"data2 = []\n",
|
||||
"for k,v in dict1.items():\n",
|
||||
" list2 = []\n",
|
||||
" \n",
|
||||
"list1 = []\n",
|
||||
"for k, v in dict2.items():\n",
|
||||
" \n",
|
||||
" if str(k) in dict1.keys():\n",
|
||||
" list2 = []\n",
|
||||
" list2 = [k,v['name'],v['sex'],v['unit'],dict1[k]['phone']] \n",
|
||||
" list1.append(list2)\n",
|
||||
"filename = 'data/宁夏能化干预人员参加问卷人员(20251010).xlsx'\n",
|
||||
" for k1,v1 in v.items():\n",
|
||||
" #list2 = []\n",
|
||||
" if k1 not in list1:\n",
|
||||
" list2.append(k1)\n",
|
||||
" list2.sort()\n",
|
||||
" \n",
|
||||
" for rq in list2:\n",
|
||||
" for k1, v1 in v[rq].items():\n",
|
||||
" data1 = []\n",
|
||||
" data1.append(rq)\n",
|
||||
" data1.append(k)\n",
|
||||
" data1.append(v['unit'])\n",
|
||||
" data1.append(v['name'])\n",
|
||||
" data1.append(v['sex'])\n",
|
||||
" data1.append(v['sex'])\n",
|
||||
" for item in xm:\n",
|
||||
" data1.append(v[rq][item])\n",
|
||||
" if 'sport_type' in v[rq].keys():\n",
|
||||
" data1.append(v[rq]['sport_type'])\n",
|
||||
" else:\n",
|
||||
" data1.append('')\n",
|
||||
" if 'sport_type' in v[rq].keys():\n",
|
||||
" data1.append(v[rq]['sport_type'])\n",
|
||||
" else:\n",
|
||||
" data1.append('')\n",
|
||||
" \n",
|
||||
" if 'sport_duration' in v[rq].keys():\n",
|
||||
" data1.append(v[rq]['sport_duration'])\n",
|
||||
" else:\n",
|
||||
" data1.append('')\n",
|
||||
" if v[rq]['recipe']=='free':\n",
|
||||
" data1.append('自行控制')\n",
|
||||
" else:\n",
|
||||
" data1.append('减脂餐')\n",
|
||||
" if v[rq]['last_sport']=='是':\n",
|
||||
" data1.append('运动时长:'+str(v[rq]['last_sport_time'])+'分钟')\n",
|
||||
" else:\n",
|
||||
" data1.append('未运动,'+v[rq]['last_sport-Comment'])\n",
|
||||
" if v[rq]['last_recipe']=='是':\n",
|
||||
" data1.append('是')\n",
|
||||
" else:\n",
|
||||
" data1.append('否。'+v[rq]['last_recipe-Comment'])\n",
|
||||
" if v[rq]['last_lose']=='是':\n",
|
||||
" data1.append('是,减重'+str(v[rq]['last_lose_weight'])+'公斤。')\n",
|
||||
" elif 'last_lose-Comment' in v[rq].keys():\n",
|
||||
" data1.append('否。'+v[rq]['last_lose-Comment'])\n",
|
||||
" else:\n",
|
||||
" data1.append('否。')\n",
|
||||
" data2.append(data1)\n",
|
||||
" \n",
|
||||
"filename = 'data/宁夏能化干预人员问卷信息(20251114).xlsx'\n",
|
||||
"wb = openpyxl.Workbook()\n",
|
||||
"sheet = wb.active\n",
|
||||
"sheet.append(title)\n",
|
||||
"for row in list1:\n",
|
||||
"for row in data2:\n",
|
||||
" sheet.append(row)\n",
|
||||
" \n",
|
||||
"wb.save(filename)"
|
||||
"wb.save(filename) "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "f32288ee-167c-4e2a-9679-5d927db34950",
|
||||
"id": "c19f04a8-64a4-4660-8359-7780de4a5227",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
|
||||
Reference in new issue
Block a user