{"id":519,"date":"2025-01-17T08:11:11","date_gmt":"2025-01-17T00:11:11","guid":{"rendered":"http:\/\/sqtcw.cn\/?p=519"},"modified":"2025-01-17T08:11:11","modified_gmt":"2025-01-17T00:11:11","slug":"python%ef%bc%9aignore_indextrue-%e5%8f%82%e6%95%b0%e5%9c%a8-pd-concat%e4%b8%ad%e6%98%af%e8%bf%9e%e6%8e%a5%e5%90%8e%e7%9a%84%e7%bb%93%e6%9e%9c%e4%bc%9a%e4%bf%9d%e7%95%99%e5%8e%9f%e6%9d%a5","status":"publish","type":"post","link":"http:\/\/www.cnitw.com\/?p=519","title":{"rendered":"Python\uff1aignore_index=True\u00a0\u53c2\u6570\u5728\u00a0pd.concat()\u4e2d\u662f\u8fde\u63a5\u540e\u7684\u7ed3\u679c\u4f1a\u4fdd\u7559\u539f\u6765\u4e24\u4e2a\u00a0DataFrame\u00a0\u7684\u7d22\u5f15\u3002"},"content":{"rendered":"\n<p>\u5b9e\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import pandas as pd\n\n# \u8bfb\u53d6 Excel \u6587\u4ef6\ndf = pd.read_excel('your_file.xlsx')\n\n# \u5047\u8bbe\u8981\u6dfb\u52a0\u7684\u6570\u636e\nnew_data = {'Column1': &#91;value1, value2,...], 'Column2': &#91;value3, value4,...],...}\n\n# \u521b\u5efa\u65b0\u7684 DataFrame\nnew_df = pd.DataFrame(new_data)\n\n# \u5c06\u65b0\u7684\u6570\u636e\u6dfb\u52a0\u5230\u539f DataFrame \u4e2d\ndf = pd.concat(&#91;df, new_df], ignore_index=True)  #\u8fde\u63a5\u540e\u7684\u7ed3\u679c\u4f1a\u4fdd\u7559\u539f\u6765\u4e24\u4e2a DataFrame \u7684\u7d22\u5f15\u3002\n\n# \u4fdd\u5b58\u4fee\u6539\u540e\u7684 Excel \u6587\u4ef6\ndf.to_excel('your_file.xlsx', index=False)ignore_index =True \n\n<\/code><\/pre>\n\n\n\n<p>ignore_index=True \u53c2\u6570\u5728 pd.concat() \u51fd\u6570\u4e2d\u662f\u53ef\u4ee5\u4e0d\u5199\u7684\u3002<br>\u5982\u679c\u4e0d\u5199 ignore_index=True \uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8fde\u63a5\u540e\u7684\u7ed3\u679c\u4f1a\u4fdd\u7559\u539f\u6765\u4e24\u4e2a DataFrame \u7684\u7d22\u5f15\u3002<br>\u5982\u679c\u5199\u4e0a ignore_index=True \uff0c\u5219\u8fde\u63a5\u540e\u7684\u7ed3\u679c\u4f1a\u91cd\u65b0\u751f\u6210\u4ece 0 \u5f00\u59cb\u7684\u8fde\u7eed\u7d22\u5f15\u3002<br>\u662f\u5426\u4f7f\u7528\u53d6\u51b3\u4e8e\u60a8\u7684\u5177\u4f53\u9700\u6c42\uff0c\u5982\u679c\u60a8\u4e0d\u5e0c\u671b\u4fdd\u7559\u539f\u6709\u7684\u7d22\u5f15\uff0c\u6216\u8005\u5e0c\u671b\u5f97\u5230\u4e00\u4e2a\u8fde\u7eed\u7684\u65b0\u7d22\u5f15\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 ignore_index=True \uff1b\u5982\u679c\u60a8\u5e0c\u671b\u4fdd\u7559\u539f\u6709\u7684\u7d22\u5f15\uff0c\u5c31\u53ef\u4ee5\u7701\u7565\u8fd9\u4e2a\u53c2\u6570\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9e\u4f8b\uff1a ignore_index=True \u53c2\u6570\u5728 pd.concat() \u51fd\u6570\u4e2d\u662f\u53ef\u4ee5\u4e0d\u5199\u7684\u3002\u5982\u679c\u4e0d\u5199 ignore_index=True \uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8fde\u63a5\u540e\u7684\u7ed3\u679c\u4f1a\u4fdd\u7559\u539f\u6765\u4e24\u4e2a DataFrame \u7684\u7d22\u5f15\u3002\u5982\u679c\u5199\u4e0a ignore_index=True \uff0c\u5219\u8fde\u63a5\u540e\u7684\u7ed3\u679c\u4f1a\u91cd\u65b0\u751f\u6210\u4ece 0 \u5f00\u59cb\u7684\u8fde\u7eed\u7d22\u5f15\u3002\u662f\u5426\u4f7f\u7528\u53d6\u51b3\u4e8e\u60a8\u7684\u5177\u4f53\u9700\u6c42\uff0c\u5982\u679c\u60a8\u4e0d\u5e0c\u671b\u4fdd\u7559\u539f\u6709\u7684\u7d22\u5f15\uff0c\u6216\u8005\u5e0c\u671b\u5f97\u5230\u4e00\u4e2a\u8fde\u7eed\u7684\u65b0\u7d22\u5f15\uff0c\u5c31\u53ef\u4ee5\u4f7f\u7528 ignore_index=True \uff1b\u5982\u679c\u60a8\u5e0c\u671b\u4fdd\u7559\u539f\u6709\u7684\u7d22\u5f15\uff0c\u5c31\u53ef\u4ee5\u7701\u7565\u8fd9\u4e2a\u53c2\u6570\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-519","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts\/519","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=519"}],"version-history":[{"count":0,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts\/519\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=519"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=519"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=519"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}