Pandas 读取 Excel 表格:跳过首行,去除索引,提取列数据
使用 pandas 库中的 read_excel 函数来读取 excel 表格,并使用 iloc 函数来提取所需的行和列。\n\n以下是实现的代码示例:\n\npython\nimport pandas as pd\n\n# 读取 excel 表格\ndf = pd.read_excel('文件路径.xlsx')\n\n# 提取第二行到最后一行的数据\ndata = df.iloc[1:, :]\n\n# 重置索引\ndata.reset_index(drop=True, inplace=True)\n\n# 提取第一列、第二列和第三列的数据并赋给三个变量\ncol1 = data.iloc[:, 0]\ncol2 = data.iloc[:, 1]\ncol3 = data.iloc[:, 2]\n\n\n其中,'文件路径.xlsx'需要替换为实际的 excel 文件路径。
原文地址: https://www.cveoy.top/t/topic/pF0L 著作权归作者所有。请勿转载和采集!