This commit is contained in:
512song committed 2025-12-03 22:24:07 +08:00
1 parent 7b02657d6d
commit 1036605b50
6 files changed
+761 -281

No files matched your search

+121 -44
View File
@@ -1270,18 +1270,55 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "2f9f474d-265c-4beb-bd0e-53372ae9e57e",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T04:26:40.331997Z",
"iopub.status.busy": "2025-12-03T04:26:40.331341Z",
"iopub.status.idle": "2025-12-03T04:26:41.149586Z",
"shell.execute_reply": "2025-12-03T04:26:41.149140Z",
"shell.execute_reply.started": "2025-12-03T04:26:40.331947Z"
},
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"<>:51: SyntaxWarning: invalid escape sequence '\\s'\n",
"<>:51: SyntaxWarning: invalid escape sequence '\\s'\n",
"/tmp/ipykernel_1730998/3799497539.py:51: SyntaxWarning: invalid escape sequence '\\s'\n",
" data =[re.sub('\\s+', '', cell) if cell is not None else None for cell in row]\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"['姓名', '邵希强']\n",
"['性别', '男']\n",
"['测试标准', '国民体质测定标准']\n",
"['身高体重指数', '26.02', '60分']\n",
"['握力', '33.5千克', '50分']\n",
"['肺活量', '3050毫升', '70分']\n",
"['选择反应时', '0.572秒', '75分']\n",
"['指标', '您的结果', '亚洲男性平均值']\n",
"['臀围', '100', '88.82']\n",
"['身高腰围指数', '53.19', '42.79']\n",
"['建议类别', '建议项']\n",
"['增加摄入', '豆类、水果、蔬菜、坚果类、蛋类、菌类、乳制品、肉类']\n",
"['生活习惯', '提高睡眠质量、保持心情舒畅、换季时避开感染源、减少用眼']\n"
]
}
],
"source": [
"import pdfplumber\n",
"import json\n",
"import re\n",
"\n",
"file = \"file/1_中石化北海炼化2020年团体体检报告.pdf\"\n",
"file = \"file/01730823-邵希强.pdf\"\n",
"pdf = pdfplumber.open(file)\n",
"list1 = []\n",
"dict1 = {}\n",
@@ -1347,58 +1384,98 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "71e1da77-6744-4d86-a4bc-88feeb3023e8",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import pdfplumber\n",
"import json\n",
"import re\n",
"\n",
"file = \"file/1_中石化北海炼化2020年团体体检报告.pdf\"\n",
"pdf = pdfplumber.open(file)\n",
"list1 = []\n",
"dict1 = {}\n",
"n = 1\n",
"for page in pdf.pages:\n",
" for pdf_table in page.extract_tables():\n",
" list2 = []\n",
" table = []\n",
" cells = []\n",
" for row in pdf_table:\n",
" print(row)\n",
" print('******')\n",
" print('--------')\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 13,
"id": "b0764366-12cf-4880-8e0f-9ae18b46d392",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T05:52:34.403674Z",
"iopub.status.busy": "2025-12-03T05:52:34.402297Z",
"iopub.status.idle": "2025-12-03T05:52:34.532929Z",
"shell.execute_reply": "2025-12-03T05:52:34.532427Z",
"shell.execute_reply.started": "2025-12-03T05:52:34.403605Z"
},
"tags": []
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[['姓名', '邵希强']]\n",
"[['性别', '男']]\n",
"[['测试标准', '国民体质测定标准']]\n",
"[['身高体重指数', '26.02', '60分']]\n",
"[['握力', '33.5 千克', '50分']]\n",
"[['肺活量', '3050 毫升', '70分']]\n",
"[['选择反应时', '0.572 秒', '75分']]\n"
]
}
],
"source": [
"import camelot\n",
"import json\n",
"import re\n",
"import pdfplumber\n",
"name = 'file/01730823-邵希强.pdf'\n",
"\n",
"file = \"file/1_中石化北海炼化2020年团体体检报告.pdf\"\n",
"tables = camelot.read_pdf(file, pages='3',flavor='stream')\n",
"# 2.导出pdf所有的表格为csv文件\n",
"tables.export('foo.json', f='json')\n",
"print('ok!')"
"pdf = pdfplumber.open(name)\n",
"tables =pdf.pages[1].extract_tables()\n",
"df1 = tables\n",
"for item in df1:\n",
" print(item)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "04dd6436-8374-4096-a2a3-d79f4d93a360",
"metadata": {
"execution": {
"iopub.execute_input": "2025-12-03T06:25:24.215544Z",
"iopub.status.busy": "2025-12-03T06:25:24.214765Z",
"iopub.status.idle": "2025-12-03T06:25:24.280529Z",
"shell.execute_reply": "2025-12-03T06:25:24.280065Z",
"shell.execute_reply.started": "2025-12-03T06:25:24.215449Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['北体乾元健康管理中心', '姓名 邵希强', '中石化(天津)石油化工 编号 01730823', '有限公司 性别 男', '年龄 53', '国民体质检测结果与健康处方', '肺活量', '握力 身高体重指数', '坐位体前屈 选择反应时', '纵跳 闭眼单脚站立', '俯卧撑', '测试标准 国民体质测定标准', '闭眼单脚站立 2.8 秒 10分', '身高体重指数 26.02 60分', '坐位体前屈 13.5 厘米 90分', '握力 33.5 千克 50分', '纵跳 18.0 厘米 30分', '肺活量 3050 毫升 70分', '俯卧撑 5 次 50分', '选择反应时 0.572 秒 75分', '腰臀比 0.90 正常', '请注意:以上测试项目及格线为3分。列表中红色项目需重点关注,建议在专家指导下进行科学锻炼,', '减少潜在的运动风险。', '感谢您完成测试,以《国民体质测定标准》综合评级,您的总分为58分,等级为四级(不合格)。', '(其中项目纵跳因超出年龄范围得分仅供参考,不计入总分)', '北体乾元体质监测报告']\n",
"11 21\n",
"闭眼单脚站立 2.8 秒 10分\n",
"身高体重指数 26.02 60分\n",
"坐位体前屈 13.5 厘米 90分\n",
"握力 33.5 千克 50分\n",
"纵跳 18.0 厘米 30分\n",
"肺活量 3050 毫升 70分\n",
"俯卧撑 5 次 50分\n",
"选择反应时 0.572 秒 75分\n",
"腰臀比 0.90 正常\n"
]
}
],
"source": [
"import pdfplumber\n",
"name = 'file/01730823-邵希强.pdf'\n",
"pdf = pdfplumber.open(name)\n",
"text = pdf.pages[1].extract_text()#######页码从0开始计数\n",
"#print(text)\n",
"list1 = text.split('\\n')\n",
"print(list1)\n",
"for item in list1:\n",
" if '测试标准 国民体质测定标准' in item:\n",
" list_min = list1.index(item)\n",
" if '请注意:以上测试项目' in item:\n",
" list_max = list1.index(item)\n",
"print(list_min,list_max)\n",
"for i in range(list_min+1,list_max):\n",
" print(list1[i])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "04dd6436-8374-4096-a2a3-d79f4d93a360",
"id": "ac034bf9-cba9-4a72-87ba-d77721cc7097",
"metadata": {},
"outputs": [],
"source": []