0
0
Pandasdata~10 mins

Reading Excel files with read_excel in Pandas - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to read an Excel file named 'data.xlsx' into a DataFrame.

Pandas
import pandas as pd

df = pd.read_excel([1])
Drag options to blanks, or click blank then click option'
A'data.xlsx'
B'data.csv'
C'data.txt'
D'data.json'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a CSV or text file name instead of an Excel file.
Forgetting to put the file name inside quotes.
2fill in blank
medium

Complete the code to read the Excel file 'report.xlsx' and select the sheet named 'Sales'.

Pandas
df = pd.read_excel('report.xlsx', sheet_name=[1])
Drag options to blanks, or click blank then click option'
A'Sheet1'
B'Summary'
C'Data'
D'Sales'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong sheet name.
Not putting the sheet name inside quotes.
3fill in blank
hard

Fix the error in the code to read only columns 'A' and 'C' from 'data.xlsx'.

Pandas
df = pd.read_excel('data.xlsx', usecols=[1])
Drag options to blanks, or click blank then click option'
A['A', 'C']
B['A:C']
C'A,C'
D'A:C'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a list instead of a string for usecols.
Using a range string like 'A:C' which selects all columns between A and C.
4fill in blank
hard

Fill both blanks to read 'file.xlsx' selecting sheet 2 and skipping the first 3 rows.

Pandas
df = pd.read_excel([1], sheet_name=[2], skiprows=3)
Drag options to blanks, or click blank then click option'
A'file.xlsx'
B'file.csv'
C1
D2
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong file extension.
Confusing sheet index with sheet name.
5fill in blank
hard

Fill all three blanks to read 'data.xlsx', parse dates in column 'Date', and set 'ID' as index.

Pandas
df = pd.read_excel([1], parse_dates=[[2]], index_col=[3])
Drag options to blanks, or click blank then click option'
A'data.csv'
B'Date'
C'ID'
D'data.xlsx'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a CSV file name instead of Excel.
Not putting the date column name inside a list.
Not setting the correct index column.