AMP

Chapter-2 Data Handling using Pandas - II — Online MCQ Test

INFORMATICS PRACTICES · Grade 12 · CBSE(NCERT)
Practice Chapter-2 Data Handling using Pandas - II with a free chapter-wise online MCQ test. This chapter covers: DataFrame operations - missing values - NaN - descriptive statistics - mean - median - mode - sorting - CSV import - CSV export. AI-generated questions from basic to board-exam level, with instant results and explanations.

Start Exam on Full Site →

Chapter-2 Data Handling using Pandas - II — Important Questions & Answers

What does NaN stand for in pandas?
  • A. Not a Number
  • B. Not a Name
  • C. Null and Null
  • D. No Available Number
Answer: A. Not a Number
NaN is a standard representation in pandas and NumPy for missing or undefined numerical values.
Which method is used to check for missing values in a pandas DataFrame?
  • A. isnull()
  • B. ismissing()
  • C. findnull()
  • D. checknull()
Answer: A. isnull()
The isnull() method returns a boolean DataFrame indicating which values are NaN or missing.
What is the correct method to import a CSV file into a pandas DataFrame?
  • A. pd.import_csv('file.csv')
  • B. pd.read_csv('file.csv')
  • C. pd.load_csv('file.csv')
  • D. pd.open_csv('file.csv')
Answer: B. pd.read_csv('file.csv')
The read_csv() function is the standard pandas method for importing CSV files into DataFrames.
Which function calculates the average value of a numerical column?
  • A. median()
  • B. mean()
  • C. average()
  • D. sum()
Answer: B. mean()
The mean() method returns the arithmetic average of numerical values in a DataFrame or Series.
If a DataFrame has missing values represented as NaN, which method fills them with the mean value?
  • A. df.fill_na()
  • B. df.fillna(df.mean())
  • C. df.replace_missing()
  • D. df.impute_mean()
Answer: B. df.fillna(df.mean())
The fillna() method combined with mean() fills NaN values with the mean of the respective column.
Consider a DataFrame with salary data containing some NaN values. Which approach would be most appropriate to handle these missing values before calculating statistics?
  • A. Delete all rows with NaN values using dropna()
  • B. Fill NaN with mean or interpolation method
  • C. Convert NaN to zero
  • D. Ignore NaN and calculate statistics anyway
Answer: B. Fill NaN with mean or interpolation method
Filling NaN with mean or interpolation preserves data integrity and sample size better than deletion or converting to zero, which can skew statistics.
Consider a student marks DataFrame. If you need to identify and count all missing values across the entire DataFrame, which method would you use?
  • A. df.count_na()
  • B. df.isnull().sum().sum()
  • C. df.missing_values()
  • D. df.count_missing()
Answer: B. df.isnull().sum().sum()
df.isnull() returns boolean values, .sum() counts NaN per column, and another .sum() totals across all columns.
A DataFrame has age values with some outliers. Which measure of central tendency would best represent the data and why?
  • A. Mean, because it uses all values
  • B. Median, because it is resistant to outliers
  • C. Mode, because it is most common
  • D. All three are equally good
Answer: B. Median, because it is resistant to outliers
Median is the best choice for data with outliers as it is position-based and not affected by extreme values.
Consider a scenario where you need to keep track of which values were originally missing after imputation. What would be the best approach?
  • A. Don't impute, just use dropna()
  • B. Create a separate boolean column marking NaN locations before imputation
  • C. Impute and then check describe() for changes
  • D. Use fillna() with a unique marker value instead of statistics
Answer: B. Create a separate boolean column marking NaN locations before imputation
Creating a mask column before imputation preserves information about original missing values for auditing and analysis.
When sorting a DataFrame with NaN values, which behavior occurs by default with sort_values()?
  • A. NaN values are placed at the end regardless of sort direction
  • B. NaN values are placed at the beginning
  • C. NaN values cause the sort to fail
  • D. NaN values are treated as the smallest values
Answer: A. NaN values are placed at the end regardless of sort direction
By default, sort_values() places NaN values at the end of sorted results, with na_position parameter controlling this behavior.