Q1. Which function is used to read an Excel file in Pandas?
A. pd.read_excel()
B. pd.load_excel()
C. pd.import_excel()
D. pd.open_excel()
Q2. Which attribute returns the column names of a DataFrame?
A. df.header
B. df.columns
C. df.names
D. df.fields
Q3. Which method returns the last 5 rows of a DataFrame by default?
A. df.bottom()
B. df.last()
C. df.tail()
D. df.end()
Q4. Which method is used to change the data type of a column?
A. astype()
B. convert()
C. dtype()
D. change_type()
Q5. What is the default join type used by pd.merge()?
A. Left Join
B. Right Join
C. Inner Join
D. Outer Join
Q6. Which method is used to remove a specific column from a DataFrame?
A. delete()
B. remove()
C. drop()
D. pop_column()
Q7. Which function returns the number of unique values in a column?
A. count_unique()
B. unique_count()
C. nunique()
D. unique()
Q8. What does df.loc[] use for indexing?
A. Integer positions
B. Labels or index names
C. Boolean values only
D. Random indexing
Q9. Which function returns all unique values in a column?
A. distinct()
B. unique()
C. values()
D. different()
Q10. Which method resets the DataFrame index?
A. reset_index()
B. new_index()
C. reindex()
D. index_reset()
Q11. Which parameter is commonly used in drop() to specify rows or columns?
A. position
B. axis
C. indexing
D. direction
Q12. Which function is used to count non-null values in each column?
A. count()
B. size()
C. describe()
D. value_counts()
Q13. What does value_counts() return?
A. Data types of columns
B. Frequency of unique values
C. Column names
D. Mean values
Q14. Which method combines DataFrames vertically or horizontally?
A. append()
B. concat()
C. merge()
D. join()
Q15. Which function is used to sort a DataFrame by its index?
A. sort_index()
B. index_sort()
C. sort_values()
D. arrange_index()
Q16. Which parameter of sort_values() determines ascending or descending order?
A. reverse
B. descending
C. ascending
D. order
Q17. Which function is used to calculate the correlation between numerical columns?
A. relation()
B. corr()
C. covariance()
D. compare()
Q18. Which function calculates cumulative sum?
A. sum()
B. cumsum()
C. cumadd()
D. running_sum()
Q19. Which function is used to randomly sample rows from a DataFrame?
A. random()
B. sample()
C. choose()
D. pick()
Q20. Which function creates a pivot table in Pandas?
A. pivot_table()
B. pivot()
C. table()
D. cross_table()
Python Pandas MCQ Quiz – Set 2 (Answers with Explanations)
Q1. Answer: A — pd.read_excel()
Explanation:pd.read_excel() is the standard Pandas function used to import Excel files (.xlsx, .xls) into a DataFrame.
Example:
import pandas as pd
df = pd.read_excel("employees.xlsx")
Q2. Answer: B — df.columns
Explanation:
The columns attribute returns all column names as an Index object.
Example:
print(df.columns)
Q3. Answer: C — df.tail()
Explanation:tail() displays the last 5 rows of a DataFrame by default.
Example:
df.tail()
df.tail(10)
Q4. Answer: A — astype()
Explanation:
The astype() method is used to convert the data type of one or more columns.
Example:
df["Age"] = df["Age"].astype(int)
Q5. Answer: C — Inner Join
Explanation:
The default join type of pd.merge() is inner, which returns only matching rows from both DataFrames.
Example:
pd.merge(df1, df2, on="ID")
Q6. Answer: C — drop()
Explanation:drop() removes rows or columns from a DataFrame.
Example:
df.drop("Salary", axis=1)
Q7. Answer: C — nunique()
Explanation:nunique() counts the number of distinct values in a Series or DataFrame column.
Example:
df["Department"].nunique()
Q8. Answer: B — Labels or index names
Explanation:loc[] performs label-based indexing using row labels and column names.
Example:
df.loc[5]df.loc[5, "Name"]
Q9. Answer: B — unique()
Explanation:unique() returns an array containing all distinct values in a column.
Example:
df["City"].unique()
Q10. Answer: A — reset_index()
Explanation:
This method resets the DataFrame index to the default integer index.
Example:
df.reset_index()
Q11. Answer: B — axis
Explanation:
The axis parameter specifies whether to drop rows (axis=0) or columns (axis=1).
Example:
df.drop("Age", axis=1)
Q12. Answer: A — count()
Explanation:count() counts only non-null values in each column.
Example:
df.count()
Q13. Answer: B — Frequency of unique values
Explanation:value_counts() displays how many times each unique value appears.
Example:
df["Department"].value_counts()
Q14. Answer: B — concat()
Explanation:concat() combines DataFrames either vertically (axis=0) or horizontally (axis=1).
Example:
pd.concat([df1, df2])
Q15. Answer: A — sort_index()
Explanation:sort_index() sorts a DataFrame based on its row or column index.
Example:
df.sort_index()
Q16. Answer: C — ascending
Explanation:
The ascending parameter controls sorting order.
ascending=True→ Smallest to largestascending=False→ Largest to smallest
Example:
df.sort_values("Salary", ascending=False)
Q17. Answer: B — corr()
Explanation:corr() computes the correlation coefficient between numerical columns.
Example:
df.corr()
Q18. Answer: B — cumsum()
Explanation:cumsum() calculates the cumulative sum of values.
Example:
df["Sales"].cumsum()
Q19. Answer: B — sample()
Explanation:sample() randomly selects rows from a DataFrame.
Example:
df.sample(5)
Q20. Answer: A — pivot_table()
Explanation:pivot_table() creates spreadsheet-style summary tables with aggregation functions.
Example:
pd.pivot_table(
df,
values="Sales",
index="Region",
aggfunc="sum"
)
Answer Key for this Python Pandas MCQ Quiz – Set 2 (Intermediate Level)
| Q. No. | Answer |
|---|---|
| 1 | A |
| 2 | B |
| 3 | C |
| 4 | A |
| 5 | C |
| 6 | C |
| 7 | C |
| 8 | B |
| 9 | B |
| 10 | A |
| 11 | B |
| 12 | A |
| 13 | B |
| 14 | B |
| 15 | A |
| 16 | C |
| 17 | B |
| 18 | B |
| 19 | B |
| 20 | A |
