{"id":487,"date":"2025-01-15T07:43:41","date_gmt":"2025-01-14T23:43:41","guid":{"rendered":"http:\/\/sqtcw.cn\/?p=487"},"modified":"2025-01-15T07:43:41","modified_gmt":"2025-01-14T23:43:41","slug":"python%e4%bd%bf%e7%94%a8-pandas-%e8%af%bb%e5%8f%96%e5%92%8c%e5%86%99%e5%85%a5-excel-%e6%96%87%e4%bb%b6%e7%9a%84%e7%ae%80%e5%8d%95%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"http:\/\/www.cnitw.com\/?p=487","title":{"rendered":"Python\u4f7f\u7528\u00a0pandas\u00a0\u8bfb\u53d6\u548c\u5199\u5165 Excel \u6587\u4ef6\u7684\u7b80\u5355\u793a\u4f8b"},"content":{"rendered":"\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 <code>pandas<\/code> \u8bfb\u53d6\u548c\u5199\u5165 Excel \u6587\u4ef6\u7684\u7b80\u5355\u793a\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('example.xlsx')\nprint(df)\n\n# \u51c6\u5907\u6570\u636e\ndata = {'Name': &#91;'Alice', 'Bob', 'Charlie'],\n        'Age': &#91;25, 30, 35],\n        'City': &#91;'New York', 'London', 'Paris']}\n\n# \u521b\u5efa DataFrame\ndf_new = pd.DataFrame(data)\n\n# \u5199\u5165 Excel \u6587\u4ef6\ndf_new.to_excel('new_example.xlsx', index=False)<\/code><\/pre>\n\n\n\n<p>\u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>pd.read_excel('example.xlsx')<\/code> \u7528\u4e8e\u8bfb\u53d6\u4e00\u4e2a\u540d\u4e3a <code>example.xlsx<\/code> \u7684 Excel \u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u5185\u5bb9\u5b58\u50a8\u4e3a <code>DataFrame<\/code> \u5bf9\u8c61 <code>df<\/code> \u3002<\/li>\n\n\n\n<li>\u7136\u540e\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5b57\u5178 <code>data<\/code> \uff0c\u5e76\u901a\u8fc7 <code>pd.DataFrame(data)<\/code> \u8f6c\u6362\u4e3a <code>DataFrame<\/code> \u5bf9\u8c61 <code>df_new<\/code> \u3002<\/li>\n\n\n\n<li>\u6700\u540e\u4f7f\u7528 <code>to_excel<\/code> \u65b9\u6cd5\u5c06 <code>df_new<\/code> \u5199\u5165\u65b0\u7684 Excel \u6587\u4ef6 <code>new_example.xlsx<\/code> \uff0c\u5e76\u8bbe\u7f6e <code>index=False<\/code> \u8868\u793a\u4e0d\u4fdd\u5b58\u7d22\u5f15\u5217\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u8bf7\u786e\u4fdd\u5c06\u6587\u4ef6\u8def\u5f84\u4fee\u6539\u4e3a\u60a8\u5b9e\u9645\u7684\u6587\u4ef6\u8def\u5f84\uff0c\u5e76\u6839\u636e\u60a8\u7684\u9700\u6c42\u4fee\u6539\u6570\u636e\u5185\u5bb9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 pandas \u8bfb\u53d6\u548c\u5199\u5165 Excel \u6587\u4ef6\u7684\u7b80\u5355\u793a\u4f8b\uff1a \u5728\u4e0a\u8ff0\u793a\u4f8b\u4e2d\uff1a \u8bf7\u786e\u4fdd\u5c06\u6587\u4ef6\u8def\u5f84\u4fee\u6539\u4e3a\u60a8\u5b9e\u9645\u7684\u6587\u4ef6\u8def\u5f84\uff0c\u5e76\u6839\u636e\u60a8\u7684\u9700\u6c42\u4fee\u6539\u6570\u636e\u5185\u5bb9\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-487","post","type-post","status-publish","format-standard","hentry","category-python"],"_links":{"self":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts\/487","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=487"}],"version-history":[{"count":0,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=\/wp\/v2\/posts\/487\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=487"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=487"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.cnitw.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=487"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}