{"id":531,"date":"2025-01-17T20:01:52","date_gmt":"2025-01-17T12:01:52","guid":{"rendered":"http:\/\/sqtcw.cn\/?p=531"},"modified":"2025-01-17T20:01:52","modified_gmt":"2025-01-17T12:01:52","slug":"python%e4%b8%adpd-read_excel-%e4%b8%8e-pd-concat-%e7%9a%84%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.cnitw.com\/?p=531","title":{"rendered":"Python\u4e2dpd.read_excel \u4e0e pd.concat \u7684\u7528\u6cd5"},"content":{"rendered":"\n<pre class=\"wp-block-code\"><code>\n\nimport os\nimport pandas as pd\n\nnb = pd.read_excel('D:\\\\EXCEL100\\\\file.xlsx')\nprint(nb)\n\ndata = {'NAE' :&#91;'DEI', 'EII' ,'EIREI']}\n\nnew = pd.DataFrame(data)\n\nnew_file = pd.concat(&#91;nb, new ] ,ignore_index= False)    #\u683c\u5f0f\u4e3a pd.concat(<mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">&#91;nb , new]<\/mark>} ) \u5728nb\u6587\u4ef6\u4e2d\u62fc\u63a5\u65b0\u6587\u4ef6 new\n\nnew_file.to_excel('D:\\\\EXCEL100\\\\file.xlsx' , index= False)<\/code><\/pre>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u7684\u76ee\u7684\u662f\u8bfb\u53d6\u4e00\u4e2a Excel \u6587\u4ef6 <code>file.xlsx<\/code> \uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u6846 <code>new<\/code> \uff0c\u7136\u540e\u5c06\u4e24\u8005\u8fde\u63a5\u8d77\u6765\u5e76\u4fdd\u5b58\u56de\u539f\u6587\u4ef6\u3002<\/p>\n\n\n\n<p class=\"has-black-color has-text-color has-link-color wp-elements-619a9870b9ab0bc5155af001ac73f046\">\u7136\u800c\uff0c\u60a8\u4ee3\u7801\u4e2d\u7684 <code>ignore_index=False<\/code> \u53ef\u80fd\u4e0d\u662f\u60a8\u671f\u671b\u7684\u3002\u5982\u679c\u4e0d\u5e0c\u671b\u7d22\u5f15\u91cd\u65b0\u7f16\u53f7\uff0c<strong>\u5efa\u8bae\u4f7f\u7528 <code>ignore_index=True<\/code> <\/strong>\uff0c\u8fd9\u6837\u8fde\u63a5\u540e\u7684\u7ed3\u679c\u4f1a\u6709\u4e00\u4e2a\u65b0\u7684\u3001\u8fde\u7eed\u7684\u7d22\u5f15\u3002<\/p>\n\n\n\n<p>\u53e6\u5916\uff0c\u60a8\u8fd8\u9700\u8981\u6ce8\u610f\uff0c\u5982\u679c\u591a\u6b21\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u4e14\u4fdd\u5b58\u56de\u540c\u4e00\u4e2a\u6587\u4ef6\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u91cd\u590d\u6216\u610f\u5916\u8986\u76d6\u3002\u5982\u679c\u60a8\u5e0c\u671b\u6bcf\u6b21\u8fd0\u884c\u90fd\u5728\u539f\u6570\u636e\u57fa\u7840\u4e0a\u8ffd\u52a0\u65b0\u6570\u636e\uff0c\u53ef\u80fd\u9700\u8981\u5148\u8bfb\u53d6\u539f\u6587\u4ef6\u6570\u636e\uff0c\u8fdb\u884c\u9002\u5f53\u5904\u7406\u540e\u518d\u4fdd\u5b58\u3002<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u6bb5\u4ee3\u7801\u7684\u76ee\u7684\u662f\u8bfb\u53d6\u4e00\u4e2a Excel \u6587\u4ef6 file.xlsx \uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u6846 new \uff0c\u7136\u540e\u5c06\u4e24\u8005\u8fde\u63a5\u8d77\u6765\u5e76\u4fdd\u5b58\u56de\u539f\u6587\u4ef6\u3002 \u7136\u800c\uff0c\u60a8\u4ee3\u7801\u4e2d\u7684 ignore_index=False \u53ef\u80fd\u4e0d\u662f\u60a8\u671f\u671b\u7684\u3002\u5982\u679c\u4e0d\u5e0c\u671b\u7d22\u5f15\u91cd\u65b0\u7f16\u53f7\uff0c\u5efa\u8bae\u4f7f\u7528 ignore_index=True \uff0c\u8fd9\u6837\u8fde\u63a5\u540e\u7684\u7ed3\u679c\u4f1a\u6709\u4e00\u4e2a\u65b0\u7684\u3001\u8fde\u7eed\u7684\u7d22\u5f15\u3002 \u53e6\u5916\uff0c\u60a8\u8fd8\u9700\u8981\u6ce8\u610f\uff0c\u5982\u679c\u591a\u6b21\u8fd0\u884c\u8fd9\u6bb5\u4ee3\u7801\u4e14\u4fdd\u5b58\u56de\u540c\u4e00\u4e2a\u6587\u4ef6\uff0c\u53ef\u80fd\u4f1a\u5bfc\u81f4\u6570\u636e\u91cd\u590d\u6216\u610f\u5916\u8986\u76d6\u3002\u5982\u679c\u60a8\u5e0c\u671b\u6bcf\u6b21\u8fd0\u884c\u90fd\u5728\u539f\u6570\u636e\u57fa\u7840\u4e0a\u8ffd\u52a0\u65b0\u6570\u636e\uff0c\u53ef\u80fd\u9700\u8981\u5148\u8bfb\u53d6\u539f\u6587\u4ef6\u6570\u636e\uff0c\u8fdb\u884c\u9002\u5f53\u5904\u7406\u540e\u518d\u4fdd\u5b58\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-531","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts\/531","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=531"}],"version-history":[{"count":0,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts\/531\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=531"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=531"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=531"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}