0
0
Pandasdata~10 mins

Writing to CSV with to_csv 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 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'
Ato_excel
Bread_csv
Csave_csv
Dto_csv
Attempts:
3 left
💡 Hint
Common Mistakes
Using read_csv instead of to_csv.
Using to_excel which saves to Excel files, not CSV.
2fill in blank
medium

Complete 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'
Aheader
Bindex
Ccolumns
Dsep
Attempts:
3 left
💡 Hint
Common Mistakes
Using header=False which hides column names.
Using sep to change separator instead of controlling index.
3fill in blank
hard

Fix 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'
Acolumns
Bindex
Cheader
Dusecols
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'usecols' which is not valid for to_csv.
Using 'index' which controls row labels, not columns.
4fill in blank
hard

Complete 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'
A;
BTrue
CFalse
D,
Attempts:
3 left
💡 Hint
Common Mistakes
Using comma as separator when semicolon is needed.
Setting header to True which keeps column names.
5fill in blank
hard

Fill 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'
Acolumns
Bindex
C\t
Dheader
Attempts:
3 left
💡 Hint
Common Mistakes
Using header instead of index to remove row labels.
Using comma instead of tab as separator.