Get startedGet started for free

Importing sheets of Excel spreadsheets

In the previous exercises, you saw that the Excel files contain two sheets, '2002' and '2004'. The next step is to import these.

In this exercise, you'll learn how to import any given sheet of your loaded .xslx file as a DataFrame. You'll be able to do so by specifying the sheet's name or its index.

The spreadsheet 'battledeath.xlsx' is already loaded as xl.

This exercise is part of the course

Importing Data in Python

View Course

Exercise instructions

  • Load the sheet 2004 into the DataFrame df1 using its name.
  • Print the head of df1 to the shell.
  • Load the sheet 2002 into the DataFrame df2 using its index.
  • Print the head of df2 to the shell.

Hands-on interactive exercise

Have a go at this exercise by completing this sample code.

# Load a sheet into a DataFrame by name: df1
df1 = xl.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(____)
Edit and Run Code