{"id":1002848,"date":"2024-12-27T10:12:20","date_gmt":"2024-12-27T02:12:20","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1002848.html"},"modified":"2024-12-27T10:12:22","modified_gmt":"2024-12-27T02:12:22","slug":"python%e5%a6%82%e4%bd%95%e5%88%b6%e4%bd%9cexcel%e8%a1%a8%e6%a0%bc","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1002848.html","title":{"rendered":"python\u5982\u4f55\u5236\u4f5cexcel\u8868\u683c"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25080434\/487eedf0-06ad-4d06-9aa3-0da847f82f92.webp\" alt=\"python\u5982\u4f55\u5236\u4f5cexcel\u8868\u683c\" \/><\/p>\n<p><p> \u4e00\u3001\u4f7f\u7528Python\u5236\u4f5cExcel\u8868\u683c\u7684\u5e38\u7528\u5e93<\/p>\n<\/p>\n<p><p>\u5236\u4f5cExcel\u8868\u683c\u5728Python\u4e2d\u975e\u5e38\u7b80\u5355\uff0c<strong>\u53ef\u4ee5\u4f7f\u7528<code>openpyxl<\/code>\u3001<code>pandas<\/code>\u3001<code>xlsxwriter<\/code>\u6765\u5904\u7406Excel\u6587\u4ef6<\/strong>\u3002\u5176\u4e2d\uff0c<code>openpyxl<\/code>\u548c<code>xlsxwriter<\/code>\u66f4\u9002\u5408\u7528\u4e8e\u521b\u5efa\u548c\u4fee\u6539.xlsx\u6587\u4ef6\uff0c\u800c<code>pandas<\/code>\u5219\u975e\u5e38\u9002\u5408\u7528\u4e8e\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u3002\u8fd9\u91cc\uff0c\u6211\u4eec\u4e3b\u8981\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528<code>openpyxl<\/code>\u5e93\u6765\u521b\u5efa\u548c\u5904\u7406Excel\u8868\u683c\u3002<\/p>\n<\/p>\n<p><p><code>openpyxl<\/code>\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u4e14\u6613\u4e8e\u4f7f\u7528\u7684\u5e93\uff0c\u5b83\u5141\u8bb8\u6211\u4eec\u521b\u5efaExcel\u6587\u4ef6\u3001\u7f16\u8f91\u5df2\u6709\u6587\u4ef6\u3001\u6dfb\u52a0\u516c\u5f0f\u3001\u683c\u5f0f\u5316\u5355\u5143\u683c\u7b49\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u901a\u8fc7Python\u7684\u5305\u7ba1\u7406\u5de5\u5177pip\u6765\u5b89\u88c5\u5b83\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install openpyxl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u4f60\u5c31\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u8fd9\u4e2a\u5e93\u5e76\u5f00\u59cb\u4f7f\u7528\u4e86\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u4f7f\u7528<code>openpyxl<\/code>\u521b\u5efa\u4e00\u4e2aExcel\u6587\u4ef6\uff0c\u5e76\u5728\u5176\u4e2d\u5199\u5165\u4e00\u4e9b\u6570\u636e\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from openpyxl import Workbook<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5de5\u4f5c\u7c3f<\/strong><\/h2>\n<p>wb = Workbook()<\/p>\n<h2><strong>\u83b7\u53d6\u6d3b\u52a8\u7684\u5de5\u4f5c\u8868<\/strong><\/h2>\n<p>ws = wb.active<\/p>\n<h2><strong>\u5728\u5355\u5143\u683c\u4e2d\u5199\u5165\u6570\u636e<\/strong><\/h2>\n<p>ws[&#39;A1&#39;] = &#39;Hello&#39;<\/p>\n<p>ws[&#39;B1&#39;] = &#39;Excel&#39;<\/p>\n<h2><strong>\u4fdd\u5b58\u5de5\u4f5c\u7c3f<\/strong><\/h2>\n<p>wb.save(&quot;sample.xlsx&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u6211\u4eec\u521b\u5efa\u4e86\u4e00\u4e2a\u65b0\u7684Excel\u5de5\u4f5c\u7c3f\uff0c\u5e76\u5728\u5176\u4e2d\u7684\u6d3b\u52a8\u5de5\u4f5c\u8868\u4e2d\u5199\u5165\u4e86\u6570\u636e\uff0c\u7136\u540e\u4fdd\u5b58\u4e3a\u4e00\u4e2a\u540d\u4e3a<code>sample.xlsx<\/code>\u7684\u6587\u4ef6\u3002<\/strong><\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u521b\u5efa\u548c\u7ba1\u7406\u5de5\u4f5c\u8868<\/p>\n<\/p>\n<p><p>\u5728Excel\u6587\u4ef6\u4e2d\uff0c\u4f60\u53ef\u4ee5\u521b\u5efa\u591a\u4e2a\u5de5\u4f5c\u8868\uff0c\u5e76\u5728\u4e0d\u540c\u7684\u5de5\u4f5c\u8868\u4e2d\u7ec4\u7ec7\u6570\u636e\u3002<code>openpyxl<\/code>\u5141\u8bb8\u4f60\u8f7b\u677e\u5730\u521b\u5efa\u548c\u7ba1\u7406\u8fd9\u4e9b\u5de5\u4f5c\u8868\u3002\u4f60\u53ef\u4ee5\u521b\u5efa\u65b0\u7684\u5de5\u4f5c\u8868\u3001\u91cd\u547d\u540d\u5df2\u6709\u7684\u5de5\u4f5c\u8868\u3001\u5220\u9664\u5de5\u4f5c\u8868\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u8981\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5de5\u4f5c\u8868\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>create_sheet<\/code>\u65b9\u6cd5\uff0c\u5e76\u53ef\u4ee5\u9009\u62e9\u6307\u5b9a\u5de5\u4f5c\u8868\u7684\u540d\u79f0\u548c\u4f4d\u7f6e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5de5\u4f5c\u8868\uff0c\u5e76\u6307\u5b9a\u540d\u79f0\u548c\u4f4d\u7f6e<\/p>\n<p>ws1 = wb.create_sheet(&quot;MySheet&quot;, 0)<\/p>\n<h2><strong>\u91cd\u547d\u540d\u5de5\u4f5c\u8868<\/strong><\/h2>\n<p>ws1.title = &quot;RenamedSheet&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8981\u5220\u9664\u4e00\u4e2a\u5de5\u4f5c\u8868\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>remove<\/code>\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5220\u9664\u5de5\u4f5c\u8868<\/p>\n<p>wb.remove(ws1)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u5728Excel\u6587\u4ef6\u4e2d\u521b\u5efa\u548c\u7ba1\u7406\u591a\u4e2a\u5de5\u4f5c\u8868\uff0c\u5e76\u6839\u636e\u9700\u8981\u7ec4\u7ec7\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u64cd\u4f5c\u5355\u5143\u683c<\/p>\n<\/p>\n<p><p>\u64cd\u4f5c\u5355\u5143\u683c\u662fExcel\u6587\u4ef6\u5904\u7406\u4e2d\u7684\u4e00\u4e2a\u91cd\u8981\u90e8\u5206\u3002<code>openpyxl<\/code>\u63d0\u4f9b\u4e86\u4e00\u4e9b\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u8bfb\u53d6\u548c\u5199\u5165\u5355\u5143\u683c\u6570\u636e\u3001\u5408\u5e76\u5355\u5143\u683c\u3001\u8bbe\u7f6e\u5355\u5143\u683c\u683c\u5f0f\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u8981\u8bfb\u53d6\u548c\u5199\u5165\u5355\u5143\u683c\u6570\u636e\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5de5\u4f5c\u8868\u5bf9\u8c61\u63d0\u4f9b\u7684\u7d22\u5f15\u8bbf\u95ee\u65b9\u5f0f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bfb\u53d6\u5355\u5143\u683c\u6570\u636e<\/p>\n<p>value = ws[&#39;A1&#39;].value<\/p>\n<h2><strong>\u5199\u5165\u5355\u5143\u683c\u6570\u636e<\/strong><\/h2>\n<p>ws[&#39;A2&#39;] = &#39;Python&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8981\u5408\u5e76\u5355\u5143\u683c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>merge_cells<\/code>\u65b9\u6cd5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5408\u5e76\u5355\u5143\u683c<\/p>\n<p>ws.merge_cells(&#39;A1:B1&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5408\u5e76\u540e\u7684\u5355\u5143\u683c\u4e2d\u53ea\u80fd\u901a\u8fc7\u5de6\u4e0a\u89d2\u7684\u5355\u5143\u683c\u6765\u8bbf\u95ee\u6216\u5199\u5165\u6570\u636e\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u8bbe\u7f6e\u5355\u5143\u683c\u683c\u5f0f<\/p>\n<\/p>\n<p><p><code>openpyxl<\/code>\u5141\u8bb8\u4f60\u8bbe\u7f6e\u5355\u5143\u683c\u7684\u683c\u5f0f\uff0c\u4f8b\u5982\u5b57\u4f53\u3001\u989c\u8272\u3001\u8fb9\u6846\u7b49\u3002\u8fd9\u4f7f\u5f97\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u521b\u5efa\u66f4\u5177\u89c6\u89c9\u5438\u5f15\u529b\u7684Excel\u8868\u683c\u3002<\/p>\n<\/p>\n<p><p>\u8981\u8bbe\u7f6e\u5355\u5143\u683c\u683c\u5f0f\uff0c\u4f60\u9700\u8981\u5bfc\u5165\u4e00\u4e9b\u76f8\u5173\u7684\u7c7b\uff0c\u4f8b\u5982<code>Font<\/code>\u3001<code>Color<\/code>\u3001<code>PatternFill<\/code>\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from openpyxl.styles import Font, Color, PatternFill<\/p>\n<h2><strong>\u8bbe\u7f6e\u5b57\u4f53<\/strong><\/h2>\n<p>ws[&#39;A1&#39;].font = Font(name=&#39;Calibri&#39;, bold=True, color=&#39;FF0000&#39;)<\/p>\n<h2><strong>\u8bbe\u7f6e\u586b\u5145\u989c\u8272<\/strong><\/h2>\n<p>ws[&#39;A1&#39;].fill = PatternFill(start_color=&#39;FFFF00&#39;, end_color=&#39;FFFF00&#39;, fill_type=&#39;solid&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u6837\u5f0f\u8bbe\u7f6e\uff0c\u4f60\u53ef\u4ee5\u81ea\u5b9a\u4e49Excel\u8868\u683c\u7684\u5916\u89c2\uff0c\u4f7f\u5176\u66f4\u7b26\u5408\u4f60\u7684\u9700\u6c42\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u4f7f\u7528\u516c\u5f0f<\/p>\n<\/p>\n<p><p>Excel\u7684\u4e00\u4e2a\u5f3a\u5927\u529f\u80fd\u662f\u652f\u6301\u4f7f\u7528\u516c\u5f0f\u6765\u8fdb\u884c\u8ba1\u7b97\u3002<code>openpyxl<\/code>\u4e5f\u652f\u6301\u5728\u5355\u5143\u683c\u4e2d\u5199\u5165\u516c\u5f0f\uff0c\u5e76\u5728Excel\u4e2d\u81ea\u52a8\u8ba1\u7b97\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>\u8981\u5728\u5355\u5143\u683c\u4e2d\u5199\u5165\u516c\u5f0f\uff0c\u4f60\u53ea\u9700\u8981\u5c06\u516c\u5f0f\u5b57\u7b26\u4e32\u8d4b\u7ed9\u5355\u5143\u683c\u5373\u53ef\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u5199\u5165\u516c\u5f0f<\/p>\n<p>ws[&#39;C1&#39;] = &#39;=SUM(A1:B1)&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5f53\u4f60\u6253\u5f00Excel\u6587\u4ef6\u65f6\uff0cExcel\u4f1a\u81ea\u52a8\u8ba1\u7b97\u5e76\u663e\u793a\u516c\u5f0f\u7684\u7ed3\u679c\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u8bfb\u53d6\u548c\u5199\u5165\u5927\u6570\u636e\u96c6<\/p>\n<\/p>\n<p><p>\u5904\u7406\u5927\u6570\u636e\u96c6\u662fExcel\u6587\u4ef6\u64cd\u4f5c\u4e2d\u7684\u5e38\u89c1\u9700\u6c42\u3002\u867d\u7136<code>openpyxl<\/code>\u80fd\u591f\u5904\u7406\u76f8\u5bf9\u8f83\u5927\u7684\u6570\u636e\u96c6\uff0c\u4f46\u5bf9\u4e8e\u975e\u5e38\u5e9e\u5927\u7684\u6570\u636e\u96c6\uff0c\u4f7f\u7528<code>pandas<\/code>\u5e93\u53ef\u80fd\u4f1a\u66f4\u9ad8\u6548\u3002<\/p>\n<\/p>\n<p><p><code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u5e76\u4e14\u80fd\u591f\u8f7b\u677e\u5730\u5c06\u6570\u636e\u5199\u5165Excel\u6587\u4ef6\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u7684<code>DataFrame<\/code>\u5bf9\u8c61\u6765\u5b58\u50a8\u548c\u64cd\u4f5c\u6570\u636e\uff0c\u7136\u540e\u4f7f\u7528<code>to_excel<\/code>\u65b9\u6cd5\u5c06\u5176\u5199\u5165Excel\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u521b\u5efa\u4e00\u4e2aDataFrame<\/strong><\/h2>\n<p>data = {&#39;Name&#39;: [&#39;Alice&#39;, &#39;Bob&#39;, &#39;Charlie&#39;],<\/p>\n<p>        &#39;Age&#39;: [25, 30, 35]}<\/p>\n<p>df = pd.DataFrame(data)<\/p>\n<h2><strong>\u5c06DataFrame\u5199\u5165Excel\u6587\u4ef6<\/strong><\/h2>\n<p>df.to_excel(&#39;data.xlsx&#39;, index=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u5f0f\u7279\u522b\u9002\u5408\u7528\u4e8e\u9700\u8981\u5bf9\u6570\u636e\u8fdb\u884c\u590d\u6742\u5904\u7406\u548c\u5206\u6790\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p>\u4e03\u3001\u7ed3\u8bba<\/p>\n<\/p>\n<p><p>\u4f7f\u7528Python\u5236\u4f5cExcel\u8868\u683c\u975e\u5e38\u65b9\u4fbf\uff0c\u5c24\u5176\u662f\u901a\u8fc7<code>openpyxl<\/code>\u548c<code>pandas<\/code>\u5e93\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u521b\u5efa\u3001\u4fee\u6539\u548c\u7ba1\u7406Excel\u6587\u4ef6\uff0c\u5e76\u6839\u636e\u9700\u8981\u8fdb\u884c\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u3002<strong>\u638c\u63e1\u8fd9\u4e9b\u5de5\u5177\u7684\u4f7f\u7528\u6280\u5de7\uff0c\u5c06\u6781\u5927\u5730\u63d0\u9ad8\u4f60\u7684\u6570\u636e\u5904\u7406\u6548\u7387<\/strong>\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\u548c\u65b9\u6cd5\uff0c\u4ee5\u5b9e\u73b0\u6700\u4f73\u6548\u679c\u3002\u65e0\u8bba\u662f\u5904\u7406\u7b80\u5355\u7684\u6570\u636e\u8868\u683c\u8fd8\u662f\u590d\u6742\u7684\u5927\u6570\u636e\u96c6\uff0cPython\u90fd\u80fd\u4e3a\u4f60\u63d0\u4f9b\u5f3a\u5927\u7684\u652f\u6301\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u521b\u5efaExcel\u6587\u4ef6\uff1f<\/strong><br \/>\u4f7f\u7528Python\u521b\u5efaExcel\u6587\u4ef6\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u5e93\u5b9e\u73b0\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f<code>pandas<\/code>\u548c<code>openpyxl<\/code>\u3002<code>pandas<\/code>\u5e93\u63d0\u4f9b\u4e86\u65b9\u4fbf\u7684\u6570\u636e\u64cd\u4f5c\u529f\u80fd\uff0c\u5141\u8bb8\u7528\u6237\u8f7b\u677e\u5730\u5c06\u6570\u636e\u6846\uff08DataFrame\uff09\u5bfc\u51fa\u4e3aExcel\u6587\u4ef6\u3002\u800c<code>openpyxl<\/code>\u5219\u66f4\u9002\u5408\u5bf9Excel\u6587\u4ef6\u8fdb\u884c\u66f4\u7ec6\u81f4\u7684\u64cd\u4f5c\uff0c\u4f8b\u5982\u8bbe\u7f6e\u5355\u5143\u683c\u683c\u5f0f\u6216\u6dfb\u52a0\u56fe\u8868\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u4f7f\u7528<code>pandas<\/code>\u8fdb\u884cExcel\u6587\u4ef6\u7684\u521b\u5efa\uff1a  <\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndata = {\n    &#39;\u59d3\u540d&#39;: [&#39;\u5f20\u4e09&#39;, &#39;\u674e\u56db&#39;, &#39;\u738b\u4e94&#39;],\n    &#39;\u5e74\u9f84&#39;: [25, 30, 22],\n    &#39;\u57ce\u5e02&#39;: [&#39;\u5317\u4eac&#39;, &#39;\u4e0a\u6d77&#39;, &#39;\u5e7f\u5dde&#39;]\n}\n\ndf = pd.DataFrame(data)\ndf.to_excel(&#39;output.xlsx&#39;, index=False)\n<\/code><\/pre>\n<p><strong>Python\u5236\u4f5cExcel\u8868\u683c\u7684\u5e38\u89c1\u5e93\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>Python\u4e2d\u6709\u51e0\u4e2a\u5e38\u7528\u7684\u5e93\u53ef\u4ee5\u7528\u6765\u5236\u4f5cExcel\u8868\u683c\uff0c\u4e3b\u8981\u5305\u62ec\uff1a  <\/p>\n<ol>\n<li><strong>pandas<\/strong>\uff1a\u7528\u4e8e\u6570\u636e\u5206\u6790\u548c\u64cd\u4f5c\uff0c\u80fd\u65b9\u4fbf\u5730\u8bfb\u5199Excel\u6587\u4ef6\u3002  <\/li>\n<li><strong>openpyxl<\/strong>\uff1a\u9002\u7528\u4e8e\u521b\u5efa\u548c\u4fee\u6539Excel 2010 xlsx\/xlsm\/xltx\/xltm\u6587\u4ef6\u3002  <\/li>\n<li><strong>xlrd\/xlwt<\/strong>\uff1a\u7528\u4e8e\u8bfb\u53d6\u548c\u5199\u5165\u65e7\u7248Excel\u6587\u4ef6\uff08xls\u683c\u5f0f\uff09\u3002  <\/li>\n<li><strong>xlsxwriter<\/strong>\uff1a\u4e13\u6ce8\u4e8e\u521b\u5efa\u65b0\u7684Excel\u6587\u4ef6\uff0c\u652f\u6301\u4e30\u5bcc\u7684\u683c\u5f0f\u548c\u56fe\u8868\u529f\u80fd\u3002<br \/>\u6839\u636e\u5177\u4f53\u9700\u6c42\uff0c\u9009\u62e9\u5408\u9002\u7684\u5e93\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002<\/li>\n<\/ol>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u5bf9Excel\u8868\u683c\u8fdb\u884c\u6570\u636e\u5904\u7406\uff1f<\/strong><br \/>\u5728Python\u4e2d\u5bf9Excel\u8868\u683c\u8fdb\u884c\u6570\u636e\u5904\u7406\u901a\u5e38\u4f7f\u7528<code>pandas<\/code>\u5e93\u3002\u8be5\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6570\u636e\u64cd\u4f5c\u529f\u80fd\uff0c\u4f8b\u5982\u8fc7\u6ee4\u3001\u5206\u7ec4\u3001\u5408\u5e76\u7b49\u3002\u901a\u8fc7<code>read_excel<\/code>\u51fd\u6570\u53ef\u4ee5\u5bfc\u5165Excel\u6587\u4ef6\u7684\u6570\u636e\u5230DataFrame\u4e2d\u8fdb\u884c\u5904\u7406\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u7801\u8bfb\u53d6Excel\u6587\u4ef6\u5e76\u8fdb\u884c\u6570\u636e\u5206\u6790\uff1a  <\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndf = pd.read_excel(&#39;input.xlsx&#39;)\n# \u8fdb\u884c\u6570\u636e\u7b5b\u9009\nfiltered_data = df[df[&#39;\u5e74\u9f84&#39;] &gt; 25]\n<\/code><\/pre>\n<p>\u901a\u8fc7\u8fd9\u4e9b\u529f\u80fd\uff0c\u60a8\u53ef\u4ee5\u8f7b\u677e\u5730\u5bf9Excel\u8868\u683c\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u5404\u79cd\u5904\u7406\u548c\u5206\u6790\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u4e00\u3001\u4f7f\u7528Python\u5236\u4f5cExcel\u8868\u683c\u7684\u5e38\u7528\u5e93 \u5236\u4f5cExcel\u8868\u683c\u5728Python\u4e2d\u975e\u5e38\u7b80\u5355\uff0c\u53ef\u4ee5\u4f7f\u7528openp [&hellip;]","protected":false},"author":3,"featured_media":1002866,"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\/1002848"}],"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=1002848"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1002848\/revisions"}],"predecessor-version":[{"id":1002868,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1002848\/revisions\/1002868"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1002866"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1002848"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1002848"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1002848"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}