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?
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)
Check how many missing values are in each column by counting empty cells.
The CSV has one missing value in each column: 'name' missing in last row, 'age' missing in Bob's row, and 'score' missing in Charlie's row. So each column has exactly one missing value.
Given two CSV strings with different separators, what is the number of rows in the DataFrame after reading each with pandas?
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)
Count the number of data rows in each CSV string after reading.
Both CSV strings have two data rows each. Using the correct separator ensures pandas reads both rows correctly.
After reading a CSV with missing values, which plot correctly shows the count of missing values per column?
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()
Look for a bar chart showing counts of missing values per column.
The code counts missing values per column and plots a bar chart. Each column has one missing value, so bars show height 1.
What error will this code raise when trying to read a CSV string with inconsistent columns?
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__)
Check what pandas does when rows have fewer columns than header.
Pandas raises a ParserError when the number of fields in a row does not match the header.
You have a CSV file where a column contains numbers and text mixed together. Which pandas option helps read this column without errors?
Think about how to allow mixed types in one column.
Setting the column dtype to 'object' allows pandas to read mixed types as strings without error.