Challenge - 5 Problems
CSV Reading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this code reading a CSV with a custom delimiter?
Consider a CSV file named
What will be the output of this code snippet?
data.csv with the following content:name|age|city Alice|30|New York Bob|25|Los Angeles
What will be the output of this code snippet?
Pandas
import pandas as pd from io import StringIO csv_data = "name|age|city\nAlice|30|New York\nBob|25|Los Angeles" df = pd.read_csv(StringIO(csv_data), delimiter='|') print(df)
Attempts:
2 left
💡 Hint
Check how the delimiter parameter changes how pandas splits columns.
✗ Incorrect
The delimiter '|' tells pandas to split columns at the pipe character. So the DataFrame has columns 'name', 'age', and 'city' with correct values.
❓ data_output
intermediate1:30remaining
How many rows does this DataFrame have after reading a CSV with skiprows?
Given a CSV content:
What is the number of rows in the DataFrame after running this code?
id,value 1,100 2,200 3,300 4,400
What is the number of rows in the DataFrame after running this code?
Pandas
import pandas as pd from io import StringIO csv_data = "id,value\n1,100\n2,200\n3,300\n4,400" df = pd.read_csv(StringIO(csv_data), skiprows=1) print(len(df))
Attempts:
2 left
💡 Hint
skiprows=1 skips the first line of the file.
✗ Incorrect
skiprows=1 skips the first line which is the header, so pandas treats the second line as header and reads 3 data rows.
🔧 Debug
advanced2:00remaining
What error does this code raise when reading a CSV with wrong header parameter?
This code tries to read a CSV but sets header=5:
What error will it raise?
import pandas as pd from io import StringIO csv_data = "a,b,c\n1,2,3\n4,5,6" df = pd.read_csv(StringIO(csv_data), header=5)
What error will it raise?
Pandas
import pandas as pd from io import StringIO csv_data = "a,b,c\n1,2,3\n4,5,6" df = pd.read_csv(StringIO(csv_data), header=5)
Attempts:
2 left
💡 Hint
Check what happens if header row index is beyond file lines.
✗ Incorrect
Setting header=5 means pandas looks for the header at line 6 (0-based), but the file has only 3 lines, so it raises a ValueError.
🚀 Application
advanced2:00remaining
Which option correctly reads a CSV file ignoring the first two rows and using the third row as header?
You have a CSV file where the first two rows are metadata and the third row contains column names. Which code reads the file correctly?
Attempts:
2 left
💡 Hint
Remember skiprows can take a list of rows to skip.
✗ Incorrect
skiprows=[0,1] skips the first two rows, then header=0 uses the next row as header. This correctly reads the third row as header.
🧠 Conceptual
expert1:30remaining
What is the effect of setting
index_col=False in pd.read_csv?When reading a CSV file, what happens if you set
index_col=False?Attempts:
2 left
💡 Hint
Check pandas documentation for index_col parameter behavior.
✗ Incorrect
Setting index_col=False tells pandas not to use any column as index, so it uses the default integer index.