Challenge - 5 Problems
CSV Mastery Badge
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 CSV with custom separator?
Given the CSV content below and the code reading it with pandas, what will be the output DataFrame?
Pandas
import pandas as pd from io import StringIO csv_data = '''name|age|city Alice|30|New York Bob|25|Los Angeles ''' df = pd.read_csv(StringIO(csv_data), sep='|') print(df)
Attempts:
2 left
💡 Hint
Check how the separator parameter affects how pandas splits columns.
✗ Incorrect
The separator '|' tells pandas to split columns at the pipe character. Without it, pandas treats the whole line as one column.
❓ data_output
intermediate2:00remaining
What is the index of the DataFrame after reading CSV with index_col?
Given this CSV and code, what will be the index values of the resulting DataFrame?
Pandas
import pandas as pd from io import StringIO csv_data = '''id,name,score 101,Alice,88 102,Bob,92 ''' df = pd.read_csv(StringIO(csv_data), index_col='id') print(df.index.tolist())
Attempts:
2 left
💡 Hint
index_col sets which column becomes the row labels (index).
✗ Incorrect
Setting index_col='id' makes the 'id' column the index, so index values are 101 and 102.
🔧 Debug
advanced2:00remaining
Why does this code raise a ParserError?
This code tries to read a CSV but raises a ParserError. What is the cause?
Pandas
import pandas as pd from io import StringIO csv_data = '''name,age,city Alice,30 Bob,25,Los Angeles ''' df = pd.read_csv(StringIO(csv_data))
Attempts:
2 left
💡 Hint
Check if all rows have the same number of columns as the header.
✗ Incorrect
The second row has only two values but the header has three columns, causing a parsing error.
🧠 Conceptual
advanced2:00remaining
How does the header parameter affect reading CSV files?
Which statement correctly describes the effect of setting header=None in pd.read_csv?
Attempts:
2 left
💡 Hint
Think about what happens if pandas does not use the first row as headers.
✗ Incorrect
Setting header=None tells pandas not to treat the first row as column names, so it uses default numbers as column names and reads the first row as data.
🚀 Application
expert3:00remaining
Which code produces a DataFrame with 'date' as index and columns 'temp' and 'humidity' from a semicolon-separated CSV?
You have a CSV with columns: date;temp;humidity. Which code correctly reads it with 'date' as index?
Attempts:
2 left
💡 Hint
Check the separator and index_col parameters carefully.
✗ Incorrect
The CSV uses semicolon separator, so sep=';' is needed. index_col='date' sets the 'date' column as index. Option A uses wrong separator, C ignores header, D uses default separator.