{"id":1103674,"date":"2025-01-08T16:12:50","date_gmt":"2025-01-08T08:12:50","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1103674.html"},"modified":"2025-01-08T16:12:53","modified_gmt":"2025-01-08T08:12:53","slug":"python%e5%a6%82%e4%bd%95%e5%b0%86%e6%95%b0%e7%bb%84%e8%be%93%e5%87%ba%e4%b8%baxls%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1103674.html","title":{"rendered":"python\u5982\u4f55\u5c06\u6570\u7ec4\u8f93\u51fa\u4e3axls\u6587\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25065404\/01012815-7092-45b1-9d45-097054a211bc.webp\" alt=\"python\u5982\u4f55\u5c06\u6570\u7ec4\u8f93\u51fa\u4e3axls\u6587\u4ef6\" \/><\/p>\n<p><p> <strong>\u5f00\u5934\u6bb5\u843d\uff1a<\/strong><\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528Pandas\u5e93\u3001\u4f7f\u7528openpyxl\u5e93\u3001\u4f7f\u7528xlwt\u5e93<\/strong>\u3002\u8981\u5c06Python\u6570\u7ec4\u8f93\u51fa\u4e3axls\u6587\u4ef6\uff0c\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u662f\u4f7f\u7528Pandas\u5e93\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u7b80\u5355\u4e14\u5f3a\u5927\u7684\u6570\u636e\u64cd\u4f5c\u529f\u80fd\u3002Pandas\u5e93\u80fd\u591f\u5f88\u65b9\u4fbf\u5730\u5c06\u6570\u636e\u6846\u67b6\uff08DataFrame\uff09\u76f4\u63a5\u5199\u5165Excel\u6587\u4ef6\u3002\u6b64\u5916\uff0copenpyxl\u5e93\u548cxlwt\u5e93\u4e5f\u662f\u5e38\u7528\u7684\u5de5\u5177\uff0c\u5b83\u4eec\u5206\u522b\u652f\u6301xlsx\u548cxls\u683c\u5f0f\u7684\u6587\u4ef6\u5199\u5165\u3002<\/p>\n<\/p>\n<p><p><strong>\u4f7f\u7528Pandas\u5e93\u662f\u6700\u63a8\u8350\u7684\u65b9\u6cd5<\/strong>\u3002Pandas\u4e0d\u4ec5\u6613\u4e8e\u4f7f\u7528\uff0c\u800c\u4e14\u5177\u6709\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u7684\u80fd\u529b\u3002\u901a\u8fc7Pandas\u5e93\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3aDataFrame\uff0c\u5e76\u4f7f\u7528<code>to_excel<\/code>\u51fd\u6570\u5c06\u5176\u5199\u5165Excel\u6587\u4ef6\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528Pandas\u5e93\uff0c\u4ee5\u53caopenpyxl\u548cxlwt\u5e93\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p><strong>\u6b63\u6587\uff1a<\/strong><\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528Pandas\u5e93<\/h3>\n<\/p>\n<p><p>Pandas\u5e93\u662fPython\u4e2d\u975e\u5e38\u5f3a\u5927\u7684\u6570\u636e\u5206\u6790\u5de5\u5177\u5e93\uff0c\u80fd\u591f\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u64cd\u4f5c\u3002\u8981\u5c06\u6570\u7ec4\u8f93\u51fa\u4e3axls\u6587\u4ef6\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u5b89\u88c5Pandas\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Pandas\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1. \u5c06\u6570\u7ec4\u8f6c\u6362\u4e3aDataFrame<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3aPandas\u7684DataFrame\u5bf9\u8c61\u3002DataFrame\u662fPandas\u4e2d\u6700\u5e38\u7528\u7684\u6570\u636e\u7ed3\u6784\u4e4b\u4e00\uff0c\u5b83\u7c7b\u4f3c\u4e8e\u7535\u5b50\u8868\u683c\u6216SQL\u8868\u683c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4<\/strong><\/h2>\n<p>data = [<\/p>\n<p>    [1, &#39;Alice&#39;, 23],<\/p>\n<p>    [2, &#39;Bob&#39;, 30],<\/p>\n<p>    [3, &#39;Charlie&#39;, 25]<\/p>\n<p>]<\/p>\n<h2><strong>\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3aDataFrame<\/strong><\/h2>\n<p>df = pd.DataFrame(data, columns=[&#39;ID&#39;, &#39;Name&#39;, &#39;Age&#39;])<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e00\u4e2a\u5305\u542b\u4e09\u884c\u6570\u636e\u7684\u6570\u7ec4\uff0c\u5e76\u5c06\u5176\u8f6c\u6362\u4e3a\u4e00\u4e2aDataFrame\u3002\u6bcf\u5217\u7684\u6570\u636e\u6709\u81ea\u5df1\u7684\u5217\u540d\uff1a&#39;ID&#39;, &#39;Name&#39;, \u548c &#39;Age&#39;\u3002<\/p>\n<\/p>\n<p><h4>2. \u5c06DataFrame\u5199\u5165Excel\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Pandas\u7684<code>to_excel<\/code>\u51fd\u6570\u5c06DataFrame\u5199\u5165Excel\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5c06DataFrame\u5199\u5165Excel\u6587\u4ef6<\/p>\n<p>df.to_excel(&#39;output.xlsx&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06DataFrame\u5199\u5165\u540d\u4e3a&#39;output.xlsx&#39;\u7684Excel\u6587\u4ef6\u3002<code>index=False<\/code>\u53c2\u6570\u8868\u793a\u4e0d\u5c06DataFrame\u7684\u7d22\u5f15\u5199\u5165Excel\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528openpyxl\u5e93<\/h3>\n<\/p>\n<p><p>openpyxl\u662f\u4e00\u4e2a\u7528\u4e8e\u8bfb\u53d6\u548c\u5199\u5165Excel 2010 xlsx\/xlsm\/xltx\/xltm\u6587\u4ef6\u7684Python\u5e93\u3002\u4e0ePandas\u4e0d\u540c\uff0copenpyxl\u662f\u4e13\u95e8\u7528\u4e8e\u5904\u7406Excel\u6587\u4ef6\u7684\u5e93\u3002\u8981\u4f7f\u7528openpyxl\uff0c\u6211\u4eec\u9700\u8981\u5148\u5b89\u88c5\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install openpyxl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1. \u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u548c\u5de5\u4f5c\u8868<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528openpyxl\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u7c3f\uff08Workbook\uff09\u548c\u4e00\u4e2a\u5de5\u4f5c\u8868\uff08Worksheet\uff09\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import openpyxl<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u7c3f<\/strong><\/h2>\n<p>wb = openpyxl.Workbook()<\/p>\n<h2><strong>\u83b7\u53d6\u6d3b\u52a8\u5de5\u4f5c\u8868<\/strong><\/h2>\n<p>ws = wb.active<\/p>\n<h2><strong>\u8bbe\u7f6e\u5de5\u4f5c\u8868\u7684\u6807\u9898<\/strong><\/h2>\n<p>ws.title = &#39;Sheet1&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u5c06\u6570\u7ec4\u5199\u5165\u5de5\u4f5c\u8868<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u7ec4\u5199\u5165\u5de5\u4f5c\u8868\u4e2d\u7684\u76f8\u5e94\u5355\u5143\u683c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4<\/p>\n<p>data = [<\/p>\n<p>    [1, &#39;Alice&#39;, 23],<\/p>\n<p>    [2, &#39;Bob&#39;, 30],<\/p>\n<p>    [3, &#39;Charlie&#39;, 25]<\/p>\n<p>]<\/p>\n<h2><strong>\u5c06\u6570\u7ec4\u5199\u5165\u5de5\u4f5c\u8868<\/strong><\/h2>\n<p>for row in data:<\/p>\n<p>    ws.append(row)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>ws.append(row)<\/code>\u65b9\u6cd5\u5c06\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u884c\u6570\u636e\u8ffd\u52a0\u5230\u5de5\u4f5c\u8868\u4e2d\u3002<\/p>\n<\/p>\n<p><h4>3. \u4fdd\u5b58\u5de5\u4f5c\u7c3f<\/h4>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5de5\u4f5c\u7c3f\u4fdd\u5b58\u4e3aExcel\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4fdd\u5b58\u5de5\u4f5c\u7c3f<\/p>\n<p>wb.save(&#39;output.xlsx&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u5de5\u4f5c\u7c3f\u4fdd\u5b58\u4e3a\u540d\u4e3a&#39;output.xlsx&#39;\u7684Excel\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528xlwt\u5e93<\/h3>\n<\/p>\n<p><p>xlwt\u662f\u4e00\u4e2a\u7528\u4e8e\u5199\u5165Excel 97-2003\u683c\u5f0f\uff08\u5373xls\u6587\u4ef6\uff09\u7684Python\u5e93\u3002\u5982\u679c\u9700\u8981\u751f\u6210xls\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528xlwt\u5e93\u3002\u8981\u4f7f\u7528xlwt\uff0c\u6211\u4eec\u9700\u8981\u5148\u5b89\u88c5\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">pip install xlwt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>1. \u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u548c\u5de5\u4f5c\u8868<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528xlwt\uff0c\u6211\u4eec\u9996\u5148\u9700\u8981\u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u7c3f\u548c\u4e00\u4e2a\u5de5\u4f5c\u8868\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import xlwt<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u7c3f<\/strong><\/h2>\n<p>wb = xlwt.Workbook()<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u5de5\u4f5c\u8868<\/strong><\/h2>\n<p>ws = wb.add_sheet(&#39;Sheet1&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u5c06\u6570\u7ec4\u5199\u5165\u5de5\u4f5c\u8868<\/h4>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u6570\u7ec4\u5199\u5165\u5de5\u4f5c\u8868\u4e2d\u7684\u76f8\u5e94\u5355\u5143\u683c\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5b9a\u4e49\u4e00\u4e2a\u6570\u7ec4<\/p>\n<p>data = [<\/p>\n<p>    [1, &#39;Alice&#39;, 23],<\/p>\n<p>    [2, &#39;Bob&#39;, 30],<\/p>\n<p>    [3, &#39;Charlie&#39;, 25]<\/p>\n<p>]<\/p>\n<h2><strong>\u5c06\u6570\u7ec4\u5199\u5165\u5de5\u4f5c\u8868<\/strong><\/h2>\n<p>for i, row in enumerate(data):<\/p>\n<p>    for j, value in enumerate(row):<\/p>\n<p>        ws.write(i, j, value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u4f7f\u7528<code>ws.write(row, col, value)<\/code>\u65b9\u6cd5\u5c06\u6570\u7ec4\u4e2d\u7684\u6bcf\u4e00\u4e2a\u503c\u5199\u5165\u5de5\u4f5c\u8868\u4e2d\u7684\u76f8\u5e94\u5355\u5143\u683c\u3002<\/p>\n<\/p>\n<p><h4>3. \u4fdd\u5b58\u5de5\u4f5c\u7c3f<\/h4>\n<\/p>\n<p><p>\u6700\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5de5\u4f5c\u7c3f\u4fdd\u5b58\u4e3aExcel\u6587\u4ef6\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4fdd\u5b58\u5de5\u4f5c\u7c3f<\/p>\n<p>wb.save(&#39;output.xls&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u5c06\u5de5\u4f5c\u7c3f\u4fdd\u5b58\u4e3a\u540d\u4e3a&#39;output.xls&#39;\u7684Excel\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u4eec\u4ecb\u7ecd\u4e86\u4e09\u79cd\u5c06Python\u6570\u7ec4\u8f93\u51fa\u4e3axls\u6587\u4ef6\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528Pandas\u5e93\u3001\u4f7f\u7528openpyxl\u5e93\u548c\u4f7f\u7528xlwt\u5e93\u3002<strong>Pandas\u5e93<\/strong>\u662f\u6700\u63a8\u8350\u7684\u65b9\u6cd5\uff0c\u56e0\u4e3a\u5b83\u4e0d\u4ec5\u6613\u4e8e\u4f7f\u7528\uff0c\u800c\u4e14\u529f\u80fd\u5f3a\u5927\uff0c\u9002\u7528\u4e8e\u5904\u7406\u5927\u578b\u6570\u636e\u96c6\u3002<strong>openpyxl\u5e93<\/strong>\u548c<strong>xlwt\u5e93<\/strong>\u5219\u5206\u522b\u9002\u7528\u4e8e\u751f\u6210xlsx\u548cxls\u6587\u4ef6\u3002\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u9ad8\u6548\u5730\u5c06Python\u6570\u7ec4\u8f93\u51fa\u4e3aExcel\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u4f7f\u7528\u54ea\u79cd\u65b9\u6cd5\uff0c\u90fd\u9700\u8981\u5148\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u9002\u5408\u5199\u5165Excel\u6587\u4ef6\u7684\u6570\u636e\u7ed3\u6784\uff0c\u7136\u540e\u5c06\u5176\u5199\u5165\u5de5\u4f5c\u8868\u4e2d\uff0c\u5e76\u4fdd\u5b58\u4e3aExcel\u6587\u4ef6\u3002\u5e0c\u671b\u672c\u6587\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u80fd\u591f\u8ba9\u4f60\u66f4\u597d\u5730\u638c\u63e1\u5c06Python\u6570\u7ec4\u8f93\u51fa\u4e3axls\u6587\u4ef6\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u5c06\u6570\u7ec4\u4fdd\u5b58\u4e3aExcel\u6587\u4ef6\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528Python\u7684pandas\u5e93\u6765\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3aExcel\u6587\u4ef6\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5df2\u5b89\u88c5pandas\u548copenpyxl\u5e93\u3002\u4f7f\u7528<code>pd.DataFrame()<\/code>\u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u6570\u636e\u6846\uff0c\u7136\u540e\u4f7f\u7528<code>to_excel()<\/code>\u65b9\u6cd5\u5c06\u5176\u4fdd\u5b58\u4e3aExcel\u6587\u4ef6\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\n# \u521b\u5efa\u4e00\u4e2a\u793a\u4f8b\u6570\u7ec4\ndata = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n\n# \u5c06\u6570\u7ec4\u8f6c\u6362\u4e3a\u6570\u636e\u6846\ndf = pd.DataFrame(data)\n\n# \u8f93\u51fa\u4e3aExcel\u6587\u4ef6\ndf.to_excel(&#39;output.xlsx&#39;, index=False)\n<\/code><\/pre>\n<p><strong>\u6211\u9700\u8981\u5b89\u88c5\u54ea\u4e9b\u5e93\u624d\u80fd\u5c06\u6570\u7ec4\u5bfc\u51fa\u4e3axls\u6587\u4ef6\uff1f<\/strong><br \/>\u4e3a\u5b8c\u6210\u8fd9\u4e2a\u64cd\u4f5c\uff0c\u60a8\u9700\u8981\u5b89\u88c5pandas\u548copenpyxl\u5e93\u3002\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u4f7f\u7528pip\u8fdb\u884c\u5b89\u88c5\uff1a  <\/p>\n<pre><code class=\"language-bash\">pip install pandas openpyxl\n<\/code><\/pre>\n<p>pandas\u7528\u4e8e\u6570\u636e\u5904\u7406\uff0copenpyxl\u5219\u662f\u7528\u4e8eExcel\u6587\u4ef6\u7684\u8bfb\u5199\u3002<\/p>\n<p><strong>\u5728\u5c06\u6570\u7ec4\u8f93\u51fa\u4e3aExcel\u6587\u4ef6\u65f6\uff0c\u6211\u53ef\u4ee5\u81ea\u5b9a\u4e49\u6587\u4ef6\u540d\u548c\u8868\u5934\u5417\uff1f<\/strong><br \/>\u662f\u7684\uff0c\u60a8\u53ef\u4ee5\u5728\u4f7f\u7528<code>to_excel()<\/code>\u65b9\u6cd5\u65f6\u81ea\u5b9a\u4e49\u6587\u4ef6\u540d\u548c\u8868\u5934\u3002\u4f8b\u5982\uff0c\u5728\u521b\u5efa\u6570\u636e\u6846\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7<code>columns<\/code>\u53c2\u6570\u8bbe\u7f6e\u8868\u5934\uff0c\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a  <\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndata = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\ndf = pd.DataFrame(data, columns=[&#39;A&#39;, &#39;B&#39;, &#39;C&#39;])\ndf.to_excel(&#39;my_data.xlsx&#39;, index=False)\n<\/code><\/pre>\n<p>\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u8868\u5934\u88ab\u8bbe\u7f6e\u4e3a&#39;A&#39;, &#39;B&#39;, &#39;C&#39;\uff0c\u8f93\u51fa\u6587\u4ef6\u540d\u4e3a&#39;my_data.xlsx&#39;\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d\uff1a \u4f7f\u7528Pandas\u5e93\u3001\u4f7f\u7528openpyxl\u5e93\u3001\u4f7f\u7528xlwt\u5e93\u3002\u8981\u5c06Python\u6570\u7ec4\u8f93\u51fa\u4e3axls\u6587\u4ef6\uff0c [&hellip;]","protected":false},"author":3,"featured_media":1103683,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1103674"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1103674"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1103674\/revisions"}],"predecessor-version":[{"id":1103688,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1103674\/revisions\/1103688"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1103683"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1103674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1103674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1103674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}