{"id":772,"date":"2023-03-28T14:37:02","date_gmt":"2023-03-28T06:37:02","guid":{"rendered":"https:\/\/kuo.us.to\/wordpress\/?p=772"},"modified":"2023-03-28T14:38:35","modified_gmt":"2023-03-28T06:38:35","slug":"python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98-%e4%b8%8d%e8%a6%8f%e5%89%87%e6%96%87%e5%ad%97%e6%aa%94%e9%97%9c%e9%8d%b5%e5%ad%97%e5%85%a7%e5%ae%b9%e8%ae%80%e5%8f%96%e3%80%81%e6%95%b4%e7%90%86%e8%88%87","status":"publish","type":"post","link":"https:\/\/kuo.us.to\/wordpress\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/772\/","title":{"rendered":"Python\u5b78\u7fd2\u7b46\u8a18: \u4e0d\u898f\u5247\u6587\u5b57\u6a94\u95dc\u9375\u5b57\u5167\u5bb9\u8b80\u53d6\u3001\u6574\u7406\u8207\u8f38\u51fa"},"content":{"rendered":"\n<p>\u672c\u6587\u4f86\u81ea\u65bcithelp\u7db2\u53cb\u4e4b\u767c\u554f\uff0c\u500b\u4eba\u53c3\u8003\u4ed6\u4ebaRegex\u5f8c\u4e4b\u7a0b\u5f0f\u89e3\u7b54\uff0c\u7db2\u5740\u5982\u4e0b\uff1a<br><a href=\"https:\/\/ithelp.ithome.com.tw\/questions\/10212370\" data-type=\"URL\" data-id=\"https:\/\/ithelp.ithome.com.tw\/questions\/10212370\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/ithelp.ithome.com.tw\/questions\/10212370<\/a><\/p>\n\n\n\n<p>test.txt\u8cc7\u6599\u6a94\u5167\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n3 i\n2 10-\n2 ,,\n1 \/ 1 cia\n0 \\ 0 0 By Pte\n\u4eba 4 6 8 \u201cPost\n-1 \/ \u201cI 5-\n2\n2 \/ TO\n-3\n4g \/ \u4eba ]\nVolume shift &#x5B;ml] 15-\n\n####Flow-Volume-Curve####\n\nPred Pre %... Post %... Chg...\nsr eff 0.96 1.13 118 0.15 89 -25\nR tot 0.30 0.48 161 1.44 146 -10\nR eff 0.30 0.42 139 0.38 127 -9\nFrcpl 2.51 1.16 74 1.79 71 -4\nVT 0.59 1.71 290 0.90 154 -47\nIc 1.91 2.44 128 2.38 125 -3\nERV 1.05 0.36 35 0.53 50 45\nRV 1.46 1.50 102 1.26 16 -16\nTLC 4.44 4.31 97 4.16 94 -3\nRV%TLC 32.90 34.78 106 30.30 92 -13\nVC IN 2.96 1.02 68 1.38 47 -32\nFVC 2.91 2.81 96 2.90 100 3\nFEV 1 2.10 2.29 92 2.38 95 4\nFEV1%F 81.65 82.08 1\nPEF 6.18 6.64 107 5.43 88 -18\nMEF 75 5.57 5.79 104 4.98 89 -14\nMEF 50 3.93 2.68 68 3.10 79 16\nMEF 25 1.71 0.88 52 1.03 60 17\nMMEF 3.46 2.24 65 2.50 72 11\nFIF 50 4.18 3.94 -6\nSubstance ventolin\n<\/pre><\/div>\n\n\n<p>\u76ee\u6a19\uff1a\u8b80\u53d6\u300cPred Pre %&#8230; Post %&#8230; Chg&#8230;\u300d\u8207\u300cSubstance ventolin\u300d\u4e4b\u9593\u7684\u5167\u5bb9\uff0c\u6574\u7406\u6210\u4ee5\u4e0b\u683c\u5f0f\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"433\" height=\"666\" src=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-28-114328.jpg\" alt=\"\" class=\"wp-image-773\" srcset=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-28-114328.jpg 433w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-28-114328-195x300.jpg 195w\" sizes=\"(max-width: 433px) 100vw, 433px\" \/><\/figure>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# \u5148\u627e\u51fa\u8b80\u53d6\u6a94\u6848\u7684\u8d77\u59cb\u548c\u7d50\u675f\u884c\nimport pandas as pd\nimport re\n\nfile = 'test.txt'\n\n# \u8a2d\u5b9a\u7a7a\u7684\u7d22\u5f15\nindexes = &#x5B;]\nwith open(file) as f:        \n    lines = f.readlines()\n    for i, line in enumerate(lines):\n        # \u641c\u5c0b\u6a94\u6848\u8981\u8b80\u53d6\u7684\u8d77\u59cb\u4f4d\u7f6e\n        if line.startswith('Pred Pre %... Post %... Chg...'):\n            # \u627e\u5230\u8d77\u59cb\u4f4d\u7f6e\u5f8c\uff0c\u4e0b\u4e00\u884c\u624d\u958b\u59cb\u8b80\u53d6\n            s = i+1\n        # \u641c\u5c0b\u6a94\u6848\u8981\u8b80\u53d6\u7684\u7d50\u675f\u4f4d\u7f6e\n        elif line.startswith('Substance ventolin'):\n            e = i\n            indexes.append((s, e))  \n        else:\n            pass\n# \u8a2d\u5b9a\u7a7a\u7684list\u5132\u5b58\u8981\u6574\u7406\u7684\u82f1\u6587\u540d\u5b57\nresult_name = &#x5B;]\n# \u8a2d\u5b9a\u7a7a\u7684list\u5132\u5b58\u8981\u6574\u7406\u7684\u6578\u64da\nresult_data = &#x5B;]\n\n# \u8b80\u53d6\u8d77\u59cb\u548c\u7d50\u675f\u4f4d\u7f6e\u4e2d\u9593\u7684\u8cc7\u6599\nfor line in lines&#x5B;s:e]:\n    \n    # \u9019\u908a\u662f\u7528ccutmis\u524d\u8f29\u7684Regex\u4f86\u5c0b\u627e\u8207\u5207\u5272\u8cc7\u6599\uff1a\n    temp = re.findall('(^&#x5B;A-Za-z%]+.*&#x5B;A-Za-z%].)(.*)$', line)\n    \n    # \u539f\u59cb\u8cc7\u6599\u4e2d\u7684\u82f1\u6587\u540d\u5b58\u5230result_name\n    result_name.append(temp&#x5B;0]&#x5B;0])\n    \n    # \u539f\u59cb\u8cc7\u6599\u4e2d\u7684\u6578\u64da\u5b58\u5230result_name\n    result_data.append(temp&#x5B;0]&#x5B;1].split(' '))\n\n\ndf_name = pd.DataFrame(result_name)\ndf_data = pd.DataFrame(result_data)\n\n# \u5c07\u4ee5\u4e0a\u76842\u500bdataframe \u4e32\u63a5\ndf = pd.concat(&#x5B;df_name, df_data], axis=1)\n# \u5c07\u6b04\u540d\u4fee\u6b63\u70ba\u300ccol_1......, col_x\u300d\ndf.columns=&#x5B;'col_' + str(x) for x in range(1, len(df.columns)+1)]\n\ndf\n<\/pre><\/div>\n\n\n<p>\u8f38\u51fa\u7d50\u679c\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" loading=\"lazy\" width=\"433\" height=\"666\" src=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-28-114328.jpg\" alt=\"\" class=\"wp-image-773\" srcset=\"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-28-114328.jpg 433w, https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/03\/Screenshot-2023-03-28-114328-195x300.jpg 195w\" sizes=\"(max-width: 433px) 100vw, 433px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u6587\u4f86\u81ea\u65bcithelp\u7db2\u53cb\u4e4b\u767c\u554f\uff0c\u500b\u4eba\u53c3\u8003\u4ed6\u4ebaRegex\u5f8c\u4e4b\u7a0b\u5f0f\u89e3\u7b54\uff0c\u7db2\u5740\u5982\u4e0b\uff1ahttps:\/\/ithelp. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":775,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advgb_blocks_editor_width":"","advgb_blocks_columns_visual_guide":"","site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}}},"categories":[4],"tags":[8,9,394,171,396,173],"author_meta":{"display_name":"mackuo","author_link":"https:\/\/kuo.us.to\/wordpress\/author\/mackuo\/"},"featured_img":"https:\/\/kuo.us.to\/wordpress\/wp-content\/uploads\/2023\/03\/hxrpsggfpqq-1-300x200.jpg","coauthors":[],"tax_additional":{"categories":{"linked":["<a href=\"https:\/\/kuo.us.to\/wordpress\/category\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/\" class=\"advgb-post-tax-term\">Python\u5b78\u7fd2\u7b46\u8a18<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">Python\u5b78\u7fd2\u7b46\u8a18<\/span>"]},"tags":{"linked":["<a href=\"https:\/\/kuo.us.to\/wordpress\/category\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/\" class=\"advgb-post-tax-term\">Pandas<\/a>","<a href=\"https:\/\/kuo.us.to\/wordpress\/category\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/\" class=\"advgb-post-tax-term\">Python<\/a>","<a href=\"https:\/\/kuo.us.to\/wordpress\/category\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/\" class=\"advgb-post-tax-term\">re<\/a>","<a href=\"https:\/\/kuo.us.to\/wordpress\/category\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/\" class=\"advgb-post-tax-term\">Regular Expression<\/a>","<a href=\"https:\/\/kuo.us.to\/wordpress\/category\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/\" class=\"advgb-post-tax-term\">\u4e0d\u898f\u5247\u6587\u5b57\u6a94<\/a>","<a href=\"https:\/\/kuo.us.to\/wordpress\/category\/python%e5%ad%b8%e7%bf%92%e7%ad%86%e8%a8%98\/\" class=\"advgb-post-tax-term\">\u6b63\u898f\u8868\u9054\u5f0f<\/a>"],"unlinked":["<span class=\"advgb-post-tax-term\">Pandas<\/span>","<span class=\"advgb-post-tax-term\">Python<\/span>","<span class=\"advgb-post-tax-term\">re<\/span>","<span class=\"advgb-post-tax-term\">Regular Expression<\/span>","<span class=\"advgb-post-tax-term\">\u4e0d\u898f\u5247\u6587\u5b57\u6a94<\/span>","<span class=\"advgb-post-tax-term\">\u6b63\u898f\u8868\u9054\u5f0f<\/span>"]}},"comment_count":"0","relative_dates":{"created":"Posted 3 \u5e74 ago","modified":"Updated 3 \u5e74 ago"},"absolute_dates":{"created":"Posted on 2023 \u5e74 3 \u6708 28 \u65e5","modified":"Updated on 2023 \u5e74 3 \u6708 28 \u65e5"},"absolute_dates_time":{"created":"Posted on 2023 \u5e74 3 \u6708 28 \u65e5 \u4e0b\u5348 2:37","modified":"Updated on 2023 \u5e74 3 \u6708 28 \u65e5 \u4e0b\u5348 2:38"},"featured_img_caption":"","series_order":"","_links":{"self":[{"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/posts\/772"}],"collection":[{"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/comments?post=772"}],"version-history":[{"count":2,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/posts\/772\/revisions"}],"predecessor-version":[{"id":777,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/posts\/772\/revisions\/777"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/media\/775"}],"wp:attachment":[{"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/media?parent=772"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/categories?post=772"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kuo.us.to\/wordpress\/wp-json\/wp\/v2\/tags?post=772"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}