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 reading a CSV with a custom separator?
Given the CSV content below saved as
data.csv with semicolon separators, what will be the output DataFrame when read with sep=';'?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), sep=';') print(df)
Attempts:
2 left
💡 Hint
Check how the separator affects parsing columns.
✗ Incorrect
Using
sep=';' correctly splits columns by semicolon, producing a DataFrame with columns 'name', 'age', and 'city'.❓ data_output
intermediate2:00remaining
What happens if header is set to None when reading CSV?
Consider this CSV content without a header row. What will be the DataFrame output when read with
header=None?Data Analysis Python
import pandas as pd from io import StringIO csv_data = '''Alice,30,New York Bob,25,Los Angeles ''' df = pd.read_csv(StringIO(csv_data), header=None) print(df)
Attempts:
2 left
💡 Hint
When header is None, pandas assigns numeric column names.
✗ Incorrect
Setting
header=None tells pandas the CSV has no header row, so it uses default numeric column names 0,1,2.❓ Predict Output
advanced2:00remaining
What error occurs when reading a CSV with wrong encoding?
Given a CSV file encoded in UTF-8 with special characters, what error will occur if read with
encoding='ascii'?Data Analysis Python
import pandas as pd from io import StringIO csv_data = 'name,city\nAna,Sevilla\nJürgen,München' df = pd.read_csv(StringIO(csv_data), encoding='ascii') print(df)
Attempts:
2 left
💡 Hint
ASCII encoding cannot decode special characters like ü.
✗ Incorrect
Using
encoding='ascii' on UTF-8 data with special characters causes a UnicodeDecodeError.❓ visualization
advanced2:00remaining
Which option correctly reads a CSV with no header and custom separator, then shows the first row?
You have a CSV with pipe '|' separator and no header. Which code snippet produces the correct first row output?
Data Analysis Python
import pandas as pd from io import StringIO csv_data = 'Alice|30|New York\nBob|25|Los Angeles' df = pd.read_csv(StringIO(csv_data), sep='|', header=None) print(df.iloc[0])
Attempts:
2 left
💡 Hint
Check how header=None affects column names and how iloc selects rows.
✗ Incorrect
With
header=None, columns are numbered 0,1,2. iloc[0] returns first row as Series with these columns.🔧 Debug
expert3:00remaining
Why does this code fail to read a CSV with UTF-16 encoding?
This code tries to read a UTF-16 encoded CSV but raises an error. What is the cause?
Data Analysis Python
import pandas as pd from io import StringIO csv_data = 'name,age\nAlice,30\nBob,25'.encode('utf-16') # Incorrect usage: df = pd.read_csv(StringIO(csv_data.decode('utf-16')), encoding='utf-16') print(df)
Attempts:
2 left
💡 Hint
Check how encoding and decoding interact when reading bytes with StringIO.
✗ Incorrect
Decoding bytes before passing to StringIO and also specifying encoding causes conflict; pandas expects raw bytes or string without encoding mismatch.