20240804
This commit is contained in:
1 parent
ae270581b1
commit
11a1e51802
5 files changed
+3130
-3048
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,
|
||||
|
||||
Reference in new issue
Block a user