0
0
Data Analysis Pythondata~20 mins

Why flexible I/O handles real-world data in Data Analysis Python - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Flexible I/O Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
What is the output of this code reading a CSV with missing values?

Consider this Python code that reads a CSV file with missing values using pandas. What will be the output of the df.isnull().sum() line?

Data Analysis Python
import pandas as pd
from io import StringIO

data = '''name,age,score
Alice,30,85
Bob,,90
Charlie,25,
,40,70
'''

# Simulate reading CSV from string
csv_data = StringIO(data)
df = pd.read_csv(csv_data)

missing_counts = df.isnull().sum()
print(missing_counts)
A{'name': 1, 'age': 1, 'score': 1}
B{'name': 0, 'age': 1, 'score': 1}
C{'name': 1, 'age': 0, 'score': 1}
D{'name': 1, 'age': 1, 'score': 0}
Attempts:
2 left
💡 Hint

Check how many missing values are in each column by counting empty cells.

data_output
intermediate
2:00remaining
How many rows are read when using flexible I/O with different separators?

Given two CSV strings with different separators, what is the number of rows in the DataFrame after reading each with pandas?

Data Analysis Python
import pandas as pd
from io import StringIO

csv_comma = 'id,name\n1,Alice\n2,Bob'
csv_semicolon = 'id;name\n3;Charlie\n4;David'

df_comma = pd.read_csv(StringIO(csv_comma))
df_semicolon = pd.read_csv(StringIO(csv_semicolon), sep=';')

rows_comma = len(df_comma)
rows_semicolon = len(df_semicolon)
print(rows_comma, rows_semicolon)
A2, 1
B2, 2
C1, 2
D1, 1
Attempts:
2 left
💡 Hint

Count the number of data rows in each CSV string after reading.

visualization
advanced
3:00remaining
Which plot shows correct handling of missing data after flexible I/O?

After reading a CSV with missing values, which plot correctly shows the count of missing values per column?

Data Analysis Python
import pandas as pd
import matplotlib.pyplot as plt
from io import StringIO

data = '''A,B,C
1,,3
4,5,
,7,9
'''

df = pd.read_csv(StringIO(data))
missing_counts = df.isnull().sum()

plt.bar(missing_counts.index, missing_counts.values)
plt.title('Missing Values per Column')
plt.ylabel('Count')
plt.show()
ABar chart with bars for A=1, B=1, C=1
BLine chart with points for A=1, B=1, C=1
CBar chart with bars for A=0, B=0, C=0
DPie chart with equal slices for A, B, C
Attempts:
2 left
💡 Hint

Look for a bar chart showing counts of missing values per column.

🔧 Debug
advanced
2:00remaining
What error does this code raise when reading a malformed CSV?

What error will this code raise when trying to read a CSV string with inconsistent columns?

Data Analysis Python
import pandas as pd
from io import StringIO

data = 'id,name\n1,Alice\n2'

try:
    df = pd.read_csv(StringIO(data))
except Exception as e:
    print(type(e).__name__)
ATypeError
BValueError
CParserError
DNo error
Attempts:
2 left
💡 Hint

Check what pandas does when rows have fewer columns than header.

🚀 Application
expert
3:00remaining
How to handle mixed data types in flexible I/O for real-world data?

You have a CSV file where a column contains numbers and text mixed together. Which pandas option helps read this column without errors?

AUse <code>na_filter=False</code> in <code>read_csv</code>
BUse <code>dtype={'column': 'int'}</code> in <code>read_csv</code>
CUse <code>skiprows=1</code> in <code>read_csv</code>
DUse <code>dtype={'column': 'object'}</code> in <code>read_csv</code>
Attempts:
2 left
💡 Hint

Think about how to allow mixed types in one column.