1. **What is Pandas primarily used for?
**
- A) Machine learning
- B) Data analysis
- C) Game development
- D) Web development
**Answer:** B) Data analysis
2. **Which of the following function in Pandas is used to check for missing values?**
- A) `isnull()`
- B) `notnull()`
- C) `isempty()`
- D) `isna()`
**Answer:** A) `isnull()`
3. **What does the `head()` function in Pandas do?**
- A) Displays the last 5 rows of a DataFrame
- B) Displays the first 5 rows of a DataFrame
- C) Displays the summary of the DataFrame
- D) Displays the column names of the DataFrame
**Answer:** B) Displays the first 5 rows of a DataFrame
4. **Which of the following methods is used to remove duplicates in a DataFrame?**
- A) `drop_duplicates()`
- B) `remove_duplicates()`
- C) `delete_duplicates()`
- D) `erase_duplicates()`
**Answer:** A) `drop_duplicates()`
5. **How do you rename a column in a Pandas DataFrame?**
- A) `df.rename(columns={})`
- B) `df.change_columns()`
- C) `df.rename_columns()`
- D) `df.modify_columns()`
**Answer:** A) `df.rename(columns={})`
6. **Which of the following will drop rows with missing values?**
- A) `dropna()`
- B) `dropna_rows()`
- C) `removena()`
- D) `delete_na()`
**Answer:** A) `dropna()`
7. **How do you reset the index of a DataFrame?**
- A) `df.reset_index()`
- B) `df.resetindex()`
- C) `df.clear_index()`
- D) `df.drop_index()`
**Answer:** A) `df.reset_index()`
8. **Which of the following functions will give you the number of rows and columns in a DataFrame?
**
- A) `df.size()`
- B) `df.shape()`
- C) `df.count()`
- D) `df.rows()`
**Answer:** B) `df.shape()`
9. **How do you create a DataFrame from a dictionary in Pandas?**
- A) `pd.DataFrame.from_dict()`
- B) `pd.DataFrame()`
- C) `pd.dict_to_df()`
- D) `pd.from_dict()`
**Answer:** B) `pd.DataFrame()`
10. **Which of the following method returns the mean of a column in Pandas?**
- A) `mean()`
- B) `average()`
- C) `sum()`
- D) `mode()`
**Answer:** A) `mean()`
11. **How do you concatenate two DataFrames vertically?**
- A) `pd.concat([df1, df2])`
- B) `pd.append([df1, df2])`
- C) `pd.merge([df1, df2])`
- D) `pd.join([df1, df2])`
**Answer:** A) `pd.concat([df1, df2])`
12. **Which of the following command will give the number of unique values in a DataFrame
column?**
- A) `nunique()`
- B) `count()`
- C) `unique()`
- D) `len()`
**Answer:** A) `nunique()`
13. **What is the default axis for the `drop()` method?**
- A) 0
- B) 1
- C) None
- D) 2
**Answer:** A) 0
14. **Which method will remove both rows and columns containing NaN values?**
- A) `dropna(how='all')`
- B) `dropna(axis='both')`
- C) `dropna()`
- D) `dropna(how='any')`
**Answer:** B) `dropna(axis='both')`
15. **Which of the following methods will give a statistical summary of numerical columns?**
- A) `describe()`
- B) `summary()`
- C) `info()`
- D) `stats()`
**Answer:** A) `describe()`
---
### **Intermediate Pandas MCQs**
1. **Which function would you use to apply a custom function to a DataFrame?**
- A) `apply()`
- B) `map()`
- C) `transform()`
- D) `groupby()`
**Answer:** A) `apply()`
2. **How do you change the datatype of a column in a DataFrame?**
- A) `df['column'].astype()`
- B) `df['column'].convert()`
- C) `df['column'].dtype()`
- D) `df['column'].type()`
**Answer:** A) `df['column'].astype()`
3. **How can you group data by a particular column in a DataFrame?**
- A) `groupby()`
- B) `aggregate()`
- C) `concat()`
- D) `group()`
**Answer:** A) `groupby()`
4. **Which of the following methods will merge two DataFrames on a specific column?**
- A) `merge()`
- B) `concat()`
- C) `join()`
- D) `combine()`
**Answer:** A) `merge()`
5. **How do you sort a DataFrame by a particular column?**
- A) `sort_values()`
- B) `order_by()`
- C) `arrange()`
- D) `sort_by()`
**Answer:** A) `sort_values()`
6. **How do you get the row with the maximum value in a column?**
- A) `idxmax()`
- B) `max()`
- C) `max_row()`
- D) `find_max()`
**Answer:** A) `idxmax()`
7. **Which method is used to handle missing data by filling it with a specific value?**
- A) `fillna()`
- B) `dropna()`
- C) `replace_na()`
- D) `impute_na()`
**Answer:** A) `fillna()`
8. **Which of the following commands will remove a column from a DataFrame?**
- A) `drop(columns='col_name')`
- B) `delete(columns='col_name')`
- C) `remove(columns='col_name')`
- D) `erase(columns='col_name')`
**Answer:** A) `drop(columns='col_name')`
9. **Which method is used to find the correlation between columns in a DataFrame?**
- A) `corr()`
- B) `correlation()`
- C) `cov()`
- D) `corrcoef()`
**Answer:** A) `corr()`
10. **What does the `pivot_table()` function in Pandas do?**
- A) Create a pivot table based on the data
- B) Transpose rows and columns
- C) Merge two DataFrames
- D) Reshape the data without pivoting
**Answer:** A) Create a pivot table based on the data
11. **Which of the following will return the cumulative sum of a column?**
- A) `cumsum()`
- B) `sum()`
- C) `cummulative_sum()`
- D) `add_cumsum()`
**Answer:** A) `cumsum()`
12. **How do you change the index of a DataFrame?**
- A) `set_index()`
- B) `reset_index()`
- C) `modify_index()`
- D) `change_index()`
**Answer:** A) `set_index()`
13. **Which of the following returns the rolling average of a column?**
- A) `rolling()`
- B) `window()`
- C) `moving()`
- D) `rollavg()`
**Answer:** A) `rolling()`
14. **Which method is used to filter rows based on conditions?**
- A) `loc[]`
- B) `filter()`
- C) `find()`
- D) `cond[]`
**Answer:** A) `loc[]`
15. **How do you create a copy of a DataFrame without affecting the original DataFrame?**
- A) `copy()`
- B) `clone()`
-C
) `duplicate()`
- D) `replicate()`
**Answer:** A) `copy()`
---
### **Hard Pandas MCQs**
1. **Which method in Pandas allows chaining multiple operations and avoids intermediate copies of
DataFrames?**
- A) `pipe()`
- B) `chain()`
- C) `flow()`
- D) `sequence()`
**Answer:** A) `pipe()`
2. **How do you apply a function element-wise across two Pandas series?**
- A) `map()`
- B) `applymap()`
- C) `apply()`
- D) `combine()`
**Answer:** D) `combine()`
3. **Which of the following will perform an inner join between two DataFrames?**
- A) `pd.merge(df1, df2, how='inner')`
- B) `pd.concat([df1, df2])`
- C) `df1.join(df2)`
- D) `pd.union(df1, df2)`
**Answer:** A) `pd.merge(df1, df2, how='inner')`
4. **How do you group a DataFrame and apply an aggregation while keeping the same shape?**
- A) `transform()`
- B) `aggregate()`
- C) `apply()`
- D) `groupby()`
**Answer:** A) `transform()`
5. **Which of the following will return a DataFrame with only the upper triangular part of a
correlation matrix?**
- A) `mask()`
- B) `triu()`
- C) `corr()`
- D) `drop_lower()`
**Answer:** B) `triu()`
6. **What will `pd.get_dummies()` function do?**
- A) Convert categorical variables into dummy/indicator variables
- B) Replace missing values
- C) Find duplicates
- D) Drop duplicates
**Answer:** A) Convert categorical variables into dummy/indicator variables
7. **How do you concatenate two DataFrames horizontally?**
- A) `pd.concat([df1, df2], axis=1)`
- B) `pd.concat([df1, df2])`
- C) `pd.append([df1, df2], axis=1)`
- D) `pd.join([df1, df2], axis=1)`
**Answer:** A) `pd.concat([df1, df2], axis=1)`
8. **Which of the following will perform a left join between two DataFrames?**
- A) `pd.merge(df1, df2, how='left')`
- B) `df1.append(df2)`
- C) `df1.join(df2)`
- D) `pd.concat([df1, df2])`
**Answer:** A) `pd.merge(df1, df2, how='left')`
9. **How do you assign rank to rows in a DataFrame?**
- A) `rank()`
- B) `sort_rank()`
- C) `order_rank()`
- D) `rank_rows()`
**Answer:** A) `rank()`
10. **Which of the following will create a time series DataFrame with daily frequency?**
- A) `pd.date_range()`
- B) `pd.time_series()`
- C) `pd.timedelta_range()`
- D) `pd.time_delta()`
**Answer:** A) `pd.date_range()`
11. **Which function is used to sample random rows from a DataFrame?**
- A) `sample()`
- B) `random_rows()`
- C) `random()`
- D) `rand_rows()`
**Answer:** A) `sample()`
12. **Which of the following will create a pivot table with custom aggregation?**
- A) `pivot_table(values='col', aggfunc='mean')`
- B) `pivot(values='col', aggfunc='mean')`
- C) `pd.pivot(values='col', mean)`
- D) `pd.create_pivot(values='col', mean)`
**Answer:** A) `pivot_table(values='col', aggfunc='mean')`
13. **Which function allows you to handle outliers in a DataFrame by capping them at a specific
quantile?**
- A) `clip()`
- B) `fillna()`
- C) `cut()`
- D) `reduce()`
**Answer:** A) `clip()`
14. **Which method is used to shift index by a specified number of periods?**
- A) `shift()`
- B) `move()`
- C) `reindex()`
- D) `period()`
**Answer:** A) `shift()`
15. **Which of the following will return the covariance matrix of numerical columns?**
- A) `cov()`
- B) `corr()`
- C) `matrix()`
- D) `cov_matrix()`
**Answer:** A) `cov()`
16. **What does the `melt()` function do in Pandas?**
- A) Reshapes a DataFrame by converting columns into rows
- B) Merges two DataFrames
- C) Sorts a DataFrame
- D) Drops missing values
**Answer:** A) Reshapes a DataFrame by converting columns into rows
17. **How do you set a column as the index of a DataFrame?**
- A) `set_index()`
- B) `df.index()`
- C) `index_column()`
- D) `add_index()`
**Answer:** A) `set_index()`
18. **Which of the following methods will unstack a multi-level index DataFrame?**
- A) `unstack()`
- B) `stack()`
- C) `pivot()`
- D) `groupby()`
**Answer:** A) `unstack()`
19. **How do you convert a DataFrame into a NumPy array?**
- A) `to_numpy()`
- B) `df.values()`
- C) `np.array(df)`
- D) `as_array()`
**Answer:** A) `to_numpy()`
20. **Which of the following functions allows for the resampling of time-series data?**
- A) `resample()`
- B) `sample()`
- C) `rescale()`
- D) `time_sample()`
**Answer:** A) `resample()`