Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to save the DataFrame to a CSV file named 'data.csv'.
Pandas
df.[1]('data.csv')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_csv instead of to_csv.
Using to_excel which saves to Excel files, not CSV.
✗ Incorrect
The to_csv method saves a DataFrame to a CSV file.
2fill in blank
mediumComplete the code to save the DataFrame without the index column.
Pandas
df.to_csv('data.csv', [1]=False)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using header=False which hides column names.
Using sep to change separator instead of controlling index.
✗ Incorrect
Setting index=False prevents saving the row numbers to the CSV.
3fill in blank
hardFix the error in saving only specific columns 'A' and 'B' to CSV.
Pandas
df.to_csv('data.csv', [1]=['A', 'B'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'usecols' which is not valid for to_csv.
Using 'index' which controls row labels, not columns.
✗ Incorrect
The columns parameter selects which columns to save.
4fill in blank
hardComplete the code to save the DataFrame with semicolon separator and no header.
Pandas
df.to_csv('data.csv', sep=';', header=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using comma as separator when semicolon is needed.
Setting header to True which keeps column names.
✗ Incorrect
Use sep=';' to change separator and header=False to omit column names.
5fill in blank
hardFill all three blanks to save only columns 'X' and 'Y', without index, and using tab as separator.
Pandas
df.to_csv('data.csv', [1]=['X', 'Y'], [2]=False, sep='[3]')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using header instead of index to remove row labels.
Using comma instead of tab as separator.
✗ Incorrect
Use columns=['X', 'Y'] to select columns, index=False to skip row labels, and sep='\t' for tab separator.