Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to save the DataFrame to an Excel file named 'data.xlsx'.
Pandas
df.to_excel([1]) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a file extension other than '.xlsx' causes the file not to be saved as Excel.
Forgetting to put the file name in quotes.
✗ Incorrect
The to_excel method requires the filename with an '.xlsx' extension to save as an Excel file.
2fill in blank
mediumComplete the code to save the DataFrame to an Excel file without including the index.
Pandas
df.to_excel('output.xlsx', [1]=False)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using header=False instead of index=False.
Misspelling the parameter name.
✗ Incorrect
Setting index=False tells pandas not to write row indices to the Excel file.
3fill in blank
hardFix the error in the code to save only specific columns 'A' and 'B' to Excel.
Pandas
df.to_excel('filtered.xlsx', [1]=['A', 'B'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using index instead of columns to select columns.
Passing columns as a string instead of a list.
✗ Incorrect
The columns parameter lets you select which columns to write to the Excel file.
4fill in blank
hardFill both blanks to save the DataFrame to an Excel file named 'report.xlsx' with the sheet named 'Summary'.
Pandas
df.to_excel([1], [2]='Summary')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong parameter name for sheet name.
Confusing file name and sheet name parameters.
✗ Incorrect
The first argument is the file name, and sheet_name='Summary' sets the sheet name.
5fill in blank
hardFill all three blanks to save the DataFrame to 'final.xlsx', without the index, and with the sheet named 'Data'.
Pandas
df.to_excel([1], [2]=False, [3]='Data')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing up parameter names.
Forgetting to put file name in quotes.
✗ Incorrect
The first blank is the file name, second is index=False to exclude indices, third is sheet_name='Data'.