开始使用免费开始使用

从 Excel 文件导入工作表

在前面的练习中,您已经看到该 Excel 文件包含两个工作表,'2002''2004'。 下一步就是导入它们。

在本练习中,您将学习如何把已加载的 .xlsx 文件中的任意 工作表导入为一个 DataFrame。您可以 通过指定工作表的名称或其索引来完成。

电子表格 'battledeath.xlsx' 已加载为 xls

本练习是课程的一部分

Python 数据导入入门

查看课程

练习说明

  • 使用名称(字符串)将工作表 '2004' 加载到 DataFrame df1 中。
  • 在终端打印 df1 的前几行。
  • 使用索引(0)将工作表 2002 加载到 DataFrame df2 中。
  • 在终端打印 df2 的前几行。

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Load a sheet into a DataFrame by name: df1
df1 = xls.parse(____)

# Print the head of the DataFrame df1
print(____)

# Load a sheet into a DataFrame by index: df2


# Print the head of the DataFrame df2
print(____)
编辑并运行代码