Q. Which method is used to replace values in a DataFrame or Series?

  • (A) fillna()
  • (B) replace()
  • (C) update()
  • (D) substitute()
πŸ’¬ Discuss
βœ… Correct Answer: (B) replace()
Explanation: The replace() method replaces specified values with another value in a DataFrame or Series.

Q. Which method is used to create a copy of a DataFrame?

  • (A) copy()
  • (B) clone()
  • (C) duplicate()
  • (D) replicate()
πŸ’¬ Discuss
βœ… Correct Answer: (A) copy()
Explanation: The copy() method creates a deep copy of a DataFrame to avoid modifying the original data.

Q. Which method returns the correlation between columns of a DataFrame?

  • (A) corr()
  • (B) cov()
  • (C) correlate()
  • (D) relationship()
πŸ’¬ Discuss
βœ… Correct Answer: (A) corr()
Explanation: The corr() method calculates pairwise correlation between numerical columns in a DataFrame.

Q. Which method is used to change the data type of a column in pandas?

  • (A) astype()
  • (B) convert()
  • (C) change_type()
  • (D) dtype()
πŸ’¬ Discuss
βœ… Correct Answer: (A) astype()
Explanation: The astype() method converts a column or Series to a specified data type.

Q. Which method is used to set a column as the index of a DataFrame?

  • (A) set_index()
  • (B) index_column()
  • (C) assign_index()
  • (D) reset_index()
πŸ’¬ Discuss
βœ… Correct Answer: (A) set_index()
Explanation: set_index() sets one or more columns as the index of the DataFrame.

Q. Which pandas function is used to check if elements in a DataFrame are null?

  • (A) isnull()
  • (B) isna()
  • (C) Both A and B
  • (D) notnull()
πŸ’¬ Discuss
βœ… Correct Answer: (C) Both A and B
Explanation: Both isnull() and isna() can be used interchangeably to detect missing values in pandas.

Q. Which method stacks the prescribed level(s) from columns to index?

  • (A) stack()
  • (B) unstack()
  • (C) melt()
  • (D) pivot()
πŸ’¬ Discuss
βœ… Correct Answer: (A) stack()
Explanation: stack() pivots the columns of a DataFrame into the index, compressing it into a Series with a MultiIndex.

Q. Which method pivots the index into columns in pandas?

  • (A) stack()
  • (B) unstack()
  • (C) pivot()
  • (D) melt()
πŸ’¬ Discuss
βœ… Correct Answer: (B) unstack()
Explanation: unstack() moves a level of the row index to the column axis, effectively pivoting it.

Q. Which method adds a new row or DataFrame to an existing DataFrame?

  • (A) append()
  • (B) concat()
  • (C) merge()
  • (D) join()
πŸ’¬ Discuss
βœ… Correct Answer: (A) append()
Explanation: append() allows adding rows or another DataFrame to an existing DataFrame along rows.

Q. Which pandas function is used to create a DataFrame from a dictionary of lists?

  • (A) pd.DataFrame()
  • (B) pd.Series()
  • (C) pd.array()
  • (D) pd.dict()
πŸ’¬ Discuss
βœ… Correct Answer: (A) pd.DataFrame()
Explanation: pd.DataFrame() can take a dictionary where keys are column names and values are lists to create a DataFrame.