0
0
Data Analysis Pythondata~10 mins

Reading Excel files (read_excel) in Data Analysis Python - 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.

Data Analysis Python
import pandas as pd

df = pd.[1]('data.xlsx')
Drag options to blanks, or click blank then click option'
Aread_excel
Bread_json
Cread_csv
Dread_table
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_csv instead of read_excel
Forgetting to import pandas
Misspelling the function name
2fill in blank
medium

Complete the code to read the Excel file 'data.xlsx' and load only the sheet named 'Sales'.

Data Analysis Python
import pandas as pd

df = pd.read_excel('data.xlsx', sheet_name=[1])
Drag options to blanks, or click blank then click option'
A'Sales'
BNone
C0
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using an integer index instead of the sheet name
Not using quotes around the sheet name
Passing None which reads all sheets
3fill in blank
hard

Fix the error in the code to read an Excel file with pandas.

Data Analysis Python
import pandas as pd

df = pd.read_excel('data.xlsx', [1]='Sales')
Drag options to blanks, or click blank then click option'
Asheetname
Bsheet_name
Csheet
Dsheetnamee
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'sheetname' without underscore
Misspelling the parameter name
Using an invalid parameter
4fill in blank
hard

Fill both blanks to read only columns 'A' and 'C' from the Excel sheet named 'Data'.

Data Analysis Python
import pandas as pd

df = pd.read_excel('file.xlsx', sheet_name=[1], usecols=[2])
Drag options to blanks, or click blank then click option'
A'Data'
B'Sales'
C['A', 'C']
D['B', 'D']
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong sheet name
Passing columns as a string instead of a list
Using incorrect column letters
5fill in blank
hard

Fill all three blanks to read the Excel file 'report.xlsx', load sheet 'Summary', and skip the first 2 rows.

Data Analysis Python
import pandas as pd

df = pd.read_excel([1], sheet_name=[2], skiprows=[3])
Drag options to blanks, or click blank then click option'
A'report.xlsx'
B'Summary'
C2
D'Data'
Attempts:
3 left
💡 Hint
Common Mistakes
Not quoting the filename or sheet name
Passing skiprows as a string instead of an integer
Using wrong sheet name