Q. Which method is used to get the shape of a DataFrame?

  • (A) shape()
  • (B) len()
  • (C) df.shape
  • (D) size()
πŸ’¬ Discuss
βœ… Correct Answer: (C) df.shape
Explanation: The shape attribute returns a tuple representing the number of rows and columns in a DataFrame.

Q. Which pandas method is used to check for duplicate rows?

  • (A) duplicated()
  • (B) drop_duplicates()
  • (C) is_duplicate()
  • (D) unique()
πŸ’¬ Discuss
βœ… Correct Answer: (A) duplicated()
Explanation: The duplicated() method returns a boolean Series indicating duplicate rows in a DataFrame.

Q. Which method converts a DataFrame to a dictionary?

  • (A) to_dict()
  • (B) to_json()
  • (C) to_array()
  • (D) as_dict()
πŸ’¬ Discuss
βœ… Correct Answer: (A) to_dict()
Explanation: The to_dict() method converts a DataFrame into a dictionary, with options for orientation.

Q. Which method is used to count non-null values in a DataFrame?

  • (A) count()
  • (B) sum()
  • (C) size()
  • (D) value_counts()
πŸ’¬ Discuss
βœ… Correct Answer: (A) count()
Explanation: The count() method returns the number of non-NA/null values for each column or row.

Q. Which pandas method is used to apply a function element-wise on a Series?

  • (A) map()
  • (B) apply()
  • (C) transform()
  • (D) aggregate()
πŸ’¬ Discuss
βœ… Correct Answer: (A) map()
Explanation: The map() method is used to apply a function or mapping to each element in a Series.

Q. Which method is used to replace multiple values in a DataFrame at once?

  • (A) fillna()
  • (B) replace()
  • (C) update()
  • (D) substitute()
πŸ’¬ Discuss
βœ… Correct Answer: (B) replace()
Explanation: The replace() method can replace multiple values at once by passing a dictionary mapping old values to new values.

Q. Which pandas function is used to read data from an Excel file?

  • (A) read_csv()
  • (B) read_excel()
  • (C) read_table()
  • (D) read_json()
πŸ’¬ Discuss
βœ… Correct Answer: (B) read_excel()
Explanation: The read_excel() function is used to read Excel files (.xls, .xlsx) into a pandas DataFrame.

Q. Which pandas method is used to change column names in-place?

  • (A) columns()
  • (B) rename(columns=..., inplace=True)
  • (C) set_columns()
  • (D) update_columns()
πŸ’¬ Discuss
βœ… Correct Answer: (B) rename(columns=..., inplace=True)
Explanation: By using rename() with the inplace=True argument, the column names can be modified directly in the existing DataFrame.

Q. Which pandas method returns the cumulative sum over a DataFrame or Series?

  • (A) cumsum()
  • (B) sum()
  • (C) cumprod()
  • (D) cummulative()
πŸ’¬ Discuss
βœ… Correct Answer: (A) cumsum()
Explanation: The cumsum() method returns a cumulative sum of the elements along a DataFrame axis or a Series.

Q. Which method is used to get the maximum value of each column in a DataFrame?

  • (A) max()
  • (B) min()
  • (C) sum()
  • (D) mean()
πŸ’¬ Discuss
βœ… Correct Answer: (A) max()
Explanation: The max() method returns the maximum value for each column in a DataFrame or Series.