{"id":1027461,"date":"2024-12-31T10:51:09","date_gmt":"2024-12-31T02:51:09","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1027461.html"},"modified":"2024-12-31T10:51:11","modified_gmt":"2024-12-31T02:51:11","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e8%8e%b7%e5%8f%96excel%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1027461.html","title":{"rendered":"\u5982\u4f55\u7528python\u83b7\u53d6excel\u6570\u636e\u7c7b\u578b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/3eded7b1-5f91-45bc-99fc-7232e2cb94ef.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u5982\u4f55\u7528python\u83b7\u53d6excel\u6570\u636e\u7c7b\u578b\" \/><\/p>\n<p><p> <strong>\u8981\u5728Python\u4e2d\u83b7\u53d6Excel\u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u4f7f\u7528\u51e0\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528pandas\u5e93\u3001openpyxl\u5e93\u548cxlrd\u5e93\u3002\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u8bfb\u53d6Excel\u6587\u4ef6\uff0c\u5e76\u6839\u636e\u5355\u5143\u683c\u7684\u5185\u5bb9\u83b7\u53d6\u5176\u6570\u636e\u7c7b\u578b\u3002<\/strong> \u5176\u4e2d\u6700\u5e38\u7528\u7684\u65b9\u5f0f\u662f\u4f7f\u7528pandas\u5e93\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\uff0c\u5e76\u4e14\u80fd\u591f\u81ea\u52a8\u63a8\u65ad\u6570\u636e\u7c7b\u578b\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u8fd9\u51e0\u79cd\u65b9\u6cd5\uff0c\u5e76\u5c55\u793a\u5982\u4f55\u4f7f\u7528\u5b83\u4eec\u6765\u83b7\u53d6Excel\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e00\u3001\u4f7f\u7528Pandas\u5e93<\/h2>\n<\/p>\n<p><p>Pandas\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6570\u636e\u5904\u7406\u548c\u5206\u6790\u5e93\uff0c\u80fd\u591f\u8f7b\u677e\u8bfb\u53d6\u548c\u5904\u7406Excel\u6587\u4ef6\u3002\u4f7f\u7528pandas\u5e93\u8bfb\u53d6Excel\u6587\u4ef6\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7DataFrame\u5bf9\u8c61\u83b7\u53d6\u6bcf\u4e2a\u5355\u5143\u683c\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5Pandas\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5pandas\u5e93\u3002\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u8bfb\u53d6Excel\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528pandas\u5e93\u8bfb\u53d6Excel\u6587\u4ef6\u975e\u5e38\u7b80\u5355\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pandas as pd<\/p>\n<h2><strong>\u8bfb\u53d6Excel\u6587\u4ef6<\/strong><\/h2>\n<p>file_path = &#39;your_excel_file.xlsx&#39;<\/p>\n<p>df = pd.read_excel(file_path)<\/p>\n<h2><strong>\u67e5\u770b\u524d\u51e0\u884c\u6570\u636e<\/strong><\/h2>\n<p>print(df.head())<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u83b7\u53d6\u6570\u636e\u7c7b\u578b<\/h3>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528DataFrame\u5bf9\u8c61\u7684<code>dtypes<\/code>\u5c5e\u6027\u6765\u83b7\u53d6\u6bcf\u5217\u7684\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u6bcf\u5217\u7684\u6570\u636e\u7c7b\u578b<\/p>\n<p>print(df.dtypes)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u6bcf\u5217\u7684\u6570\u636e\u7c7b\u578b\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code>Column1    int64<\/p>\n<p>Column2    float64<\/p>\n<p>Column3    object<\/p>\n<p>dtype: object<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4\u3001\u68c0\u67e5\u5355\u5143\u683c\u6570\u636e\u7c7b\u578b<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u9700\u8981\u68c0\u67e5\u7279\u5b9a\u5355\u5143\u683c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u4f7f\u7528<code>iloc<\/code>\u5c5e\u6027\u5e76\u7ed3\u5408<code>type<\/code>\u51fd\u6570\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u83b7\u53d6\u7279\u5b9a\u5355\u5143\u683c\u7684\u6570\u636e\u7c7b\u578b<\/p>\n<p>cell_value = df.iloc[0, 0]<\/p>\n<p>print(type(cell_value))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u5355\u5143\u683c\u7684\u6570\u636e\u7c7b\u578b\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code>&lt;class &#39;int&#39;&gt;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u4f7f\u7528Openpyxl\u5e93<\/h2>\n<\/p>\n<p><p>Openpyxl\u662f\u4e00\u4e2a\u7528\u4e8e\u8bfb\u5199Excel\u6587\u4ef6\u7684Python\u5e93\uff0c\u7279\u522b\u9002\u7528\u4e8e\u5904\u7406.xlsx\u683c\u5f0f\u7684\u6587\u4ef6\u3002\u4f7f\u7528openpyxl\u5e93\u53ef\u4ee5\u66f4\u7cbe\u7ec6\u5730\u63a7\u5236Excel\u6587\u4ef6\u7684\u8bfb\u53d6\u548c\u5199\u5165\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5Openpyxl\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5openpyxl\u5e93\u3002\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install openpyxl<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u8bfb\u53d6Excel\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528openpyxl\u5e93\u8bfb\u53d6Excel\u6587\u4ef6\u7684\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import openpyxl<\/p>\n<h2><strong>\u8bfb\u53d6Excel\u6587\u4ef6<\/strong><\/h2>\n<p>file_path = &#39;your_excel_file.xlsx&#39;<\/p>\n<p>workbook = openpyxl.load_workbook(file_path)<\/p>\n<p>sheet = workbook.active<\/p>\n<h2><strong>\u83b7\u53d6\u5355\u5143\u683c\u7684\u503c\u548c\u6570\u636e\u7c7b\u578b<\/strong><\/h2>\n<p>cell_value = sheet[&#39;A1&#39;].value<\/p>\n<p>print(cell_value)<\/p>\n<p>print(type(cell_value))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u904d\u5386\u5355\u5143\u683c\u83b7\u53d6\u6570\u636e\u7c7b\u578b<\/h3>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u904d\u5386\u6574\u4e2a\u5de5\u4f5c\u8868\uff0c\u5e76\u83b7\u53d6\u6bcf\u4e2a\u5355\u5143\u683c\u7684\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for row in sheet.iter_rows():<\/p>\n<p>    for cell in row:<\/p>\n<p>        print(cell.value, type(cell.value))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528Xlrd\u5e93<\/h2>\n<\/p>\n<p><p>Xlrd\u5e93\u662f\u4e00\u4e2a\u7528\u4e8e\u8bfb\u53d6Excel\u6587\u4ef6\u7684Python\u5e93\uff0c\u7279\u522b\u9002\u7528\u4e8e\u5904\u7406.xls\u683c\u5f0f\u7684\u6587\u4ef6\u3002\u5c3d\u7ba1xlrd\u5e93\u4e3b\u8981\u7528\u4e8e\u8bfb\u53d6\u65e7\u7248Excel\u6587\u4ef6\uff0c\u4f46\u5b83\u4ecd\u7136\u662f\u4e00\u4e2a\u975e\u5e38\u6709\u7528\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u5b89\u88c5Xlrd\u5e93<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u5b89\u88c5xlrd\u5e93\u3002\u5982\u679c\u4f60\u8fd8\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install xlrd<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u8bfb\u53d6Excel\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528xlrd\u5e93\u8bfb\u53d6Excel\u6587\u4ef6\u7684\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import xlrd<\/p>\n<h2><strong>\u8bfb\u53d6Excel\u6587\u4ef6<\/strong><\/h2>\n<p>file_path = &#39;your_excel_file.xls&#39;<\/p>\n<p>workbook = xlrd.open_workbook(file_path)<\/p>\n<p>sheet = workbook.sheet_by_index(0)<\/p>\n<h2><strong>\u83b7\u53d6\u5355\u5143\u683c\u7684\u503c\u548c\u6570\u636e\u7c7b\u578b<\/strong><\/h2>\n<p>cell_value = sheet.cell_value(0, 0)<\/p>\n<p>print(cell_value)<\/p>\n<p>print(type(cell_value))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u904d\u5386\u5355\u5143\u683c\u83b7\u53d6\u6570\u636e\u7c7b\u578b<\/h3>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u904d\u5386\u6574\u4e2a\u5de5\u4f5c\u8868\uff0c\u5e76\u83b7\u53d6\u6bcf\u4e2a\u5355\u5143\u683c\u7684\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">for row_idx in range(sheet.nrows):<\/p>\n<p>    for col_idx in range(sheet.ncols):<\/p>\n<p>        cell_value = sheet.cell_value(row_idx, col_idx)<\/p>\n<p>        print(cell_value, type(cell_value))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u7efc\u5408\u5bf9\u6bd4<\/h2>\n<\/p>\n<p><h3>1\u3001Pandas\u5e93\u7684\u4f18\u52bf<\/h3>\n<\/p>\n<p><p>Pandas\u5e93\u5728\u5904\u7406\u6570\u636e\u65b9\u9762\u975e\u5e38\u5f3a\u5927\uff0c\u80fd\u591f\u81ea\u52a8\u63a8\u65ad\u6570\u636e\u7c7b\u578b\uff0c\u5e76\u63d0\u4f9b\u4e30\u5bcc\u7684\u6570\u636e\u5904\u7406\u529f\u80fd\u3002\u5bf9\u4e8e\u5927\u591a\u6570\u6570\u636e\u5206\u6790\u4efb\u52a1\uff0cpandas\u662f\u4e00\u4e2a\u975e\u5e38\u597d\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><h3>2\u3001Openpyxl\u5e93\u7684\u4f18\u52bf<\/h3>\n<\/p>\n<p><p>Openpyxl\u5e93\u9002\u7528\u4e8e\u5904\u7406.xlsx\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u80fd\u591f\u63d0\u4f9b\u66f4\u7ec6\u7c92\u5ea6\u7684\u63a7\u5236\uff0c\u9002\u5408\u9700\u8981\u5bf9Excel\u6587\u4ef6\u8fdb\u884c\u590d\u6742\u64cd\u4f5c\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><h3>3\u3001Xlrd\u5e93\u7684\u4f18\u52bf<\/h3>\n<\/p>\n<p><p>Xlrd\u5e93\u9002\u7528\u4e8e\u5904\u7406.xls\u683c\u5f0f\u7684\u6587\u4ef6\uff0c\u5c3d\u7ba1\u5b83\u7684\u529f\u80fd\u8f83\u4e3a\u6709\u9650\uff0c\u4f46\u5728\u5904\u7406\u65e7\u7248Excel\u6587\u4ef6\u65f6\u4ecd\u7136\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><h2>\u4e94\u3001\u5b9e\u9645\u5e94\u7528\u573a\u666f<\/h2>\n<\/p>\n<p><p>\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u4f60\u53ef\u80fd\u9700\u8981\u6839\u636e\u5177\u4f53\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u9700\u8981\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u5904\u7406\uff0cpandas\u5e93\u662f\u4e00\u4e2a\u975e\u5e38\u597d\u7684\u9009\u62e9\uff1b\u5982\u679c\u4f60\u9700\u8981\u5bf9.xlsx\u6587\u4ef6\u8fdb\u884c\u590d\u6742\u64cd\u4f5c\uff0copenpyxl\u5e93\u53ef\u80fd\u66f4\u9002\u5408\uff1b\u5982\u679c\u4f60\u9700\u8981\u5904\u7406\u65e7\u7248Excel\u6587\u4ef6\uff0cxlrd\u5e93\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u6570\u636e\u5206\u6790\u4e0e\u5904\u7406<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u636e\u5206\u6790\u548c\u5904\u7406\u4efb\u52a1\u4e2d\uff0cpandas\u5e93\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u529f\u80fd\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528pandas\u5e93\u8bfb\u53d6Excel\u6587\u4ef6\uff0c\u5e76\u8fdb\u884c\u6570\u636e\u6e05\u6d17\u3001\u6570\u636e\u8f6c\u6362\u548c\u6570\u636e\u5206\u6790\u7b49\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u6570\u636e\u6e05\u6d17<\/p>\n<p>df.dropna(inplace=True)<\/p>\n<h2><strong>\u6570\u636e\u8f6c\u6362<\/strong><\/h2>\n<p>df[&#39;Column1&#39;] = df[&#39;Column1&#39;].astype(&#39;int&#39;)<\/p>\n<h2><strong>\u6570\u636e\u5206\u6790<\/strong><\/h2>\n<p>mean_value = df[&#39;Column1&#39;].mean()<\/p>\n<p>print(mean_value)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u590d\u6742\u7684Excel\u64cd\u4f5c<\/h3>\n<\/p>\n<p><p>\u5728\u9700\u8981\u8fdb\u884c\u590d\u6742Excel\u64cd\u4f5c\u7684\u573a\u666f\u4e2d\uff0copenpyxl\u5e93\u63d0\u4f9b\u4e86\u66f4\u591a\u7684\u63a7\u5236\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528openpyxl\u5e93\u521b\u5efa\u56fe\u8868\u3001\u8bbe\u7f6e\u5355\u5143\u683c\u683c\u5f0f\u548c\u5408\u5e76\u5355\u5143\u683c\u7b49\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u521b\u5efa\u56fe\u8868<\/p>\n<p>from openpyxl.chart import BarChart, Reference<\/p>\n<p>chart = BarChart()<\/p>\n<p>data = Reference(sheet, min_col=1, min_row=1, max_col=3, max_row=10)<\/p>\n<p>chart.add_data(data, titles_from_data=True)<\/p>\n<p>sheet.add_chart(chart, &#39;E5&#39;)<\/p>\n<h2><strong>\u8bbe\u7f6e\u5355\u5143\u683c\u683c\u5f0f<\/strong><\/h2>\n<p>cell = sheet[&#39;A1&#39;]<\/p>\n<p>cell.font = openpyxl.styles.Font(bold=True)<\/p>\n<p>cell.fill = openpyxl.styles.PatternFill(start_color=&#39;FFFF00&#39;, end_color=&#39;FFFF00&#39;, fill_type=&#39;solid&#39;)<\/p>\n<h2><strong>\u5408\u5e76\u5355\u5143\u683c<\/strong><\/h2>\n<p>sheet.merge_cells(&#39;A1:C1&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3\u3001\u5904\u7406\u65e7\u7248Excel\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5728\u9700\u8981\u5904\u7406\u65e7\u7248Excel\u6587\u4ef6\u7684\u573a\u666f\u4e2d\uff0cxlrd\u5e93\u662f\u4e00\u4e2a\u5408\u9002\u7684\u9009\u62e9\u3002\u4f8b\u5982\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528xlrd\u5e93\u8bfb\u53d6.xls\u6587\u4ef6\uff0c\u5e76\u8fdb\u884c\u6570\u636e\u63d0\u53d6\u7b49\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># \u8bfb\u53d6\u6570\u636e<\/p>\n<p>data = []<\/p>\n<p>for row_idx in range(sheet.nrows):<\/p>\n<p>    row_data = []<\/p>\n<p>    for col_idx in range(sheet.ncols):<\/p>\n<p>        cell_value = sheet.cell_value(row_idx, col_idx)<\/p>\n<p>        row_data.append(cell_value)<\/p>\n<p>    data.append(row_data)<\/p>\n<p>print(data)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<hr>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u4ecb\u7ecd\uff0c\u6211\u4eec\u8be6\u7ec6\u8ba8\u8bba\u4e86\u5982\u4f55\u7528Python\u83b7\u53d6Excel\u6570\u636e\u7c7b\u578b\uff0c\u5305\u62ec\u4f7f\u7528pandas\u5e93\u3001openpyxl\u5e93\u548cxlrd\u5e93\u7684\u65b9\u6cd5\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u72ec\u7279\u7684\u4f18\u52bf\uff0c\u9009\u62e9\u5408\u9002\u7684\u5e93\u53ef\u4ee5\u6839\u636e\u5177\u4f53\u9700\u6c42\u548c\u6570\u636e\u683c\u5f0f\u6765\u51b3\u5b9a\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u638c\u63e1\u8fd9\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u4f60\u66f4\u9ad8\u6548\u5730\u5904\u7406\u548c\u5206\u6790Excel\u6570\u636e\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8bfb\u53d6Excel\u6587\u4ef6\u7684\u6570\u636e\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528<code>pandas<\/code>\u5e93\u6765\u8bfb\u53d6Excel\u6587\u4ef6\u3002\u9996\u5148\uff0c\u786e\u4fdd\u5b89\u88c5\u4e86\u8be5\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip install pandas openpyxl<\/code>\u547d\u4ee4\u3002\u7136\u540e\uff0c\u4f7f\u7528<code>pandas.read_excel()<\/code>\u51fd\u6570\u6765\u52a0\u8f7dExcel\u6587\u4ef6\uff0c\u5e76\u901a\u8fc7<code>DataFrame<\/code>\u7ed3\u6784\u67e5\u770b\u6570\u636e\u3002\u793a\u4f8b\u4ee3\u7801\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">import pandas as pd\n\ndf = pd.read_excel(&#39;\u6587\u4ef6\u8def\u5f84.xlsx&#39;)\nprint(df)\n<\/code><\/pre>\n<p><strong>Python\u652f\u6301\u54ea\u4e9b\u5e93\u6765\u5904\u7406Excel\u6587\u4ef6\uff1f<\/strong><br \/>Python\u6709\u591a\u4e2a\u5e93\u53ef\u4ee5\u5904\u7406Excel\u6587\u4ef6\uff0c\u5176\u4e2d\u6700\u5e38\u7528\u7684\u662f<code>pandas<\/code>\u548c<code>openpyxl<\/code>\u3002<code>pandas<\/code>\u9002\u5408\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u5904\u7406\uff0c\u800c<code>openpyxl<\/code>\u5219\u66f4\u9002\u5408\u4e8e\u521b\u5efa\u548c\u7f16\u8f91Excel\u6587\u4ef6\u3002\u8fd8\u6709<code>xlrd<\/code>\u548c<code>xlwt<\/code>\u7b49\u5e93\uff0c\u5206\u522b\u7528\u4e8e\u8bfb\u53d6\u548c\u5199\u5165\u65e7\u7248Excel\u6587\u4ef6\u3002<\/p>\n<p><strong>\u5982\u4f55\u8bc6\u522bExcel\u6587\u4ef6\u4e2d\u5355\u5143\u683c\u7684\u6570\u636e\u7c7b\u578b\uff1f<\/strong><br \/>\u5728\u4f7f\u7528<code>pandas<\/code>\u8bfb\u53d6Excel\u6587\u4ef6\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7<code>DataFrame.dtypes<\/code>\u5c5e\u6027\u6765\u67e5\u770b\u6bcf\u4e00\u5217\u7684\u6570\u636e\u7c7b\u578b\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code class=\"language-python\">print(df.dtypes)\n<\/code><\/pre>\n<p>\u8fd9\u5c06\u663e\u793a\u6bcf\u5217\u7684\u540d\u79f0\u53ca\u5176\u5bf9\u5e94\u7684\u6570\u636e\u7c7b\u578b\uff0c\u5982\u6574\u6570\u3001\u6d6e\u70b9\u6570\u3001\u5b57\u7b26\u4e32\u7b49\u3002\u901a\u8fc7\u8fd9\u79cd\u65b9\u5f0f\uff0c\u53ef\u4ee5\u8f7b\u677e\u4e86\u89e3Excel\u6587\u4ef6\u4e2d\u6570\u636e\u7684\u7ed3\u6784\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u8981\u5728Python\u4e2d\u83b7\u53d6Excel\u6570\u636e\u7c7b\u578b\uff0c\u53ef\u4ee5\u4f7f\u7528\u51e0\u79cd\u65b9\u6cd5\uff0c\u5305\u62ec\u4f7f\u7528pandas\u5e93\u3001openpyxl\u5e93\u548cxlr [&hellip;]","protected":false},"author":3,"featured_media":1027472,"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\/1027461"}],"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=1027461"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1027461\/revisions"}],"predecessor-version":[{"id":1027474,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1027461\/revisions\/1027474"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1027472"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1027461"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1027461"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1027461"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}