0
0
Pandasdata~10 mins

read_csv parameters (sep, header, index_col) 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 read a CSV file using a comma as the separator.

Pandas
import pandas as pd

df = pd.read_csv('data.csv', sep=[1])
Drag options to blanks, or click blank then click option'
A,
B'|'
C';'
D'\t'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a semicolon or tab as separator when the file uses commas.
Leaving the separator blank when the file uses commas.
2fill in blank
medium

Complete the code to read a CSV file where the first row is the header.

Pandas
import pandas as pd

df = pd.read_csv('data.csv', header=[1])
Drag options to blanks, or click blank then click option'
A0
Bnull
C1
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using null when the file actually has headers.
Using 1 which means the second row is header.
3fill in blank
hard

Fix the error in reading a CSV file by setting the correct index column.

Pandas
import pandas as pd

df = pd.read_csv('data.csv', index_col=[1])
Drag options to blanks, or click blank then click option'
Anull
B0
C1
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using null when the file has an index column.
Using 1 which selects the second column as index.
4fill in blank
hard

Fill both blanks to read a CSV file with a tab separator and no header row.

Pandas
import pandas as pd

df = pd.read_csv('data.csv', sep=[1], header=[2])
Drag options to blanks, or click blank then click option'
A'\t'
Bnull
C0
D','
Attempts:
3 left
💡 Hint
Common Mistakes
Using comma as separator for tab-separated files.
Setting header to 0 when there is no header row.
5fill in blank
hard

Fill all three blanks to read a CSV file with pipe separator, first row as header, and second column as index.

Pandas
import pandas as pd

df = pd.read_csv('data.csv', sep=[1], header=[2], index_col=[3])
Drag options to blanks, or click blank then click option'
A'|'
B0
C1
D','
Attempts:
3 left
💡 Hint
Common Mistakes
Using comma as separator for pipe-separated files.
Setting index_col to 0 instead of 1.