20240828
This commit is contained in:
1 parent
11a1e51802
commit
724bf28fbf
12 files changed
+708
-446
No files matched your search
+147
-1
@@ -92,6 +92,52 @@
|
||||
"print('ok')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "691cbb33-47df-4235-8e20-78fb1b5aafc0",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## 转换人员信息"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"id": "be91abd1-4f95-4d82-9adb-4a38464a0f0e",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-08-11T10:46:44.484824Z",
|
||||
"iopub.status.busy": "2024-08-11T10:46:44.484083Z",
|
||||
"iopub.status.idle": "2024-08-11T10:46:44.496331Z",
|
||||
"shell.execute_reply": "2024-08-11T10:46:44.495225Z",
|
||||
"shell.execute_reply.started": "2024-08-11T10:46:44.484756Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"12\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"\n",
|
||||
"filename = 'data/世纪花园基础数据240808.json'\n",
|
||||
"with open(filename,'r') as fl:\n",
|
||||
" dict1 = json.load(fl)\n",
|
||||
"\n",
|
||||
"dict2 = {}\n",
|
||||
"for k, v in dict1.items():\n",
|
||||
" dict1[k]['phone'] = str(k)\n",
|
||||
"\n",
|
||||
"with open(filename,'w') as fl:\n",
|
||||
" json.dump(dict1, fl, ensure_ascii=False) \n",
|
||||
"print(len(dict1))"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "0dc90cf8-0a51-49ab-8f93-81acfd359e63",
|
||||
@@ -492,6 +538,106 @@
|
||||
" "
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"id": "563d553e-1629-458b-ad03-4abfeb9fbc7f",
|
||||
"metadata": {
|
||||
"execution": {
|
||||
"iopub.execute_input": "2024-08-07T23:49:52.126604Z",
|
||||
"iopub.status.busy": "2024-08-07T23:49:52.125976Z",
|
||||
"iopub.status.idle": "2024-08-07T23:49:52.148956Z",
|
||||
"shell.execute_reply": "2024-08-07T23:49:52.148516Z",
|
||||
"shell.execute_reply.started": "2024-08-07T23:49:52.126549Z"
|
||||
}
|
||||
},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"12\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import json\n",
|
||||
"import datetime\n",
|
||||
"import csv\n",
|
||||
"\n",
|
||||
"list1 = []\n",
|
||||
"filename = 'data/Survey_20240808.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[1]\n",
|
||||
" content = json.loads(item[5])\n",
|
||||
" \n",
|
||||
" name = content['name']\n",
|
||||
" sex = content['gender']\n",
|
||||
" birth = content['birth']\n",
|
||||
" unit = content['unit']\n",
|
||||
" del content['name']\n",
|
||||
" del content['gender']\n",
|
||||
" del content['birth']\n",
|
||||
" del content['unit'] \n",
|
||||
" for k, v in content.items(): \n",
|
||||
" if 'O' in k:\n",
|
||||
" age = 'O'\n",
|
||||
" psy =[]\n",
|
||||
" for i in range(1,31):\n",
|
||||
" m_key = 'q'+str(i)+'O'\n",
|
||||
" psy.append(content[m_key])\n",
|
||||
" if 'M' in k:\n",
|
||||
" psy =[]\n",
|
||||
" age = 'M'\n",
|
||||
" for i in range(1,48):\n",
|
||||
" m_key = 'q'+str(i)+'M'\n",
|
||||
" psy.append(content[m_key])\n",
|
||||
" if '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",
|
||||
" if 'v' in k:\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(phone,{})\n",
|
||||
" \n",
|
||||
" dict1[phone]['name'] = name\n",
|
||||
" dict1[phone]['sex'] = sex\n",
|
||||
" dict1[phone]['birth'] = birth\n",
|
||||
" dict1[phone]['age'] = age\n",
|
||||
" dict1[phone]['unit'] = unit\n",
|
||||
" dict1[phone]['psy'] = psy\n",
|
||||
" dict1[phone]['spine'] = spine\n",
|
||||
" dict1[phone]['tcm'] = tcm\n",
|
||||
" \n",
|
||||
" \n",
|
||||
" #list3.append(list2)\n",
|
||||
"filename = 'data/世纪花园基础数据240808.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",
|
||||
@@ -633,7 +779,7 @@
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.10.12"
|
||||
"version": "3.12.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
|
||||
Reference in new issue
Block a user