Challenge - 5 Problems
CSV Reading Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of reading CSV with specific delimiter
What is the output DataFrame when reading the CSV content with a semicolon delimiter?
Data Analysis Python
import pandas as pd from io import StringIO csv_data = '''name;age;city Alice;30;New York Bob;25;Los Angeles Charlie;35;Chicago''' df = pd.read_csv(StringIO(csv_data), delimiter=';') df
Attempts:
2 left
💡 Hint
Check how the delimiter parameter affects parsing.
✗ Incorrect
Using delimiter=';' correctly splits the columns. The DataFrame shows three columns with proper data types.
❓ data_output
intermediate1:30remaining
Number of rows after reading CSV with skiprows
How many rows does the DataFrame have after reading the CSV while skipping the first data row?
Data Analysis Python
import pandas as pd from io import StringIO csv_data = '''name,age,city Alice,30,New York Bob,25,Los Angeles Charlie,35,Chicago''' df = pd.read_csv(StringIO(csv_data), skiprows=[1]) len(df)
Attempts:
2 left
💡 Hint
skiprows removes the specified rows from the file before parsing.
✗ Incorrect
Skipping row 1 removes the first data row 'Alice,30,New York', so only Bob and Charlie remain, total 2 rows.
🔧 Debug
advanced2:00remaining
Identify the error when reading CSV with wrong header parameter
What error occurs when running this code?
Data Analysis Python
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), header=2) df
Attempts:
2 left
💡 Hint
header=2 means the third line is used as header.
✗ Incorrect
Since the CSV has only 3 lines, header=2 uses the third line 'Bob,25,Los Angeles' as header, resulting in an empty DataFrame with those column names.
🚀 Application
advanced2:30remaining
Reading CSV with missing values and filling them
Given a CSV with missing values, which code correctly reads it and fills missing ages with 0?
Data Analysis Python
import pandas as pd from io import StringIO csv_data = '''name,age,city Alice,30,New York Bob,,Los Angeles Charlie,35,Chicago''' df = pd.read_csv(StringIO(csv_data)) df['age'] = df['age'].fillna(0) df
Attempts:
2 left
💡 Hint
fillna replaces NaN values with the given value.
✗ Incorrect
fillna(0) replaces missing ages with 0. The age column becomes float because of NaN presence.
🧠 Conceptual
expert2:00remaining
Effect of dtype parameter in read_csv
What is the effect of setting dtype={'age': str} when reading a CSV file?
Attempts:
2 left
💡 Hint
dtype controls the data type of specific columns during import.
✗ Incorrect
Setting dtype={'age': str} forces pandas to treat the 'age' column as strings, useful to keep formatting like leading zeros.