Complete the code to read an Excel file named 'data.xlsx' into a DataFrame.
import pandas as pd df = pd.read_excel([1])
The read_excel function reads Excel files. The filename must end with .xlsx to read an Excel file.
Complete the code to read the Excel file 'report.xlsx' and select the sheet named 'Sales'.
df = pd.read_excel('report.xlsx', sheet_name=[1])
The sheet_name parameter lets you choose which sheet to read. Here, the sheet is named 'Sales'.
Fix the error in the code to read only columns 'A' and 'C' from 'data.xlsx'.
df = pd.read_excel('data.xlsx', usecols=[1])
usecols.The usecols parameter accepts a string like 'A,C' to select columns A and C.
Fill both blanks to read 'file.xlsx' selecting sheet 2 and skipping the first 3 rows.
df = pd.read_excel([1], sheet_name=[2], skiprows=3)
The file name must be 'file.xlsx'. Sheet 2 is selected by index 1 (0-based index means sheet 0 is first, so 1 is second sheet).
Fill all three blanks to read 'data.xlsx', parse dates in column 'Date', and set 'ID' as index.
df = pd.read_excel([1], parse_dates=[[2]], index_col=[3])
The file name is 'data.xlsx'. The parse_dates parameter takes a list of column names to convert to dates. The index_col sets the index column.