Monday 27 November 2023

Python Pandas MCQs Set 1

 

MCQs based on Python Pandas


10 important MCQs related to Python Pandas, along with their answers:


1. What is the purpose of the pandas library?

(a) To perform data analysis and manipulation

(b) To create web applications

(c) To handle machine learning tasks

(d) To visualize data


2. What is the difference between a DataFrame and a Series in Pandas?

(a) A DataFrame is a two-dimensional data structure, while a Series is a one-dimensional data structure.

(b) A DataFrame can store data of different types, while a Series can only store data of a single type.

(c) A DataFrame is like an Excel worksheet, while a Series is like a column of an Excel worksheet.

(d) All of the above


3. What is the output of the following code?

import pandas as pd

data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [32, 25, 27]}
df = pd.DataFrame(data)

print(df['Age'].max())


(a) 27

(b) 25

(c) 32

(d) None of these


4. Which of the following is not a built-in data structure in Pandas?

(a) Series

(b) DataFrame

(c) Panel

(d) Numpy ndarray


5. What is the purpose of the head() function in Pandas?

(a) To print the first few rows of a DataFrame

(b) To sort a DataFrame by a specific column

(c) To calculate the mean of a DataFrame

(d) To create a new DataFrame from an existing DataFrame


6. What is the purpose of the tail() function in Pandas?

(a) To print the first few rows of a DataFrame

(b) To sort a DataFrame by a specific column

(c) To calculate the mean of a DataFrame

(d) To create a new DataFrame from an existing DataFrame


7. What is the purpose of the dropna() function in Pandas?

(a) To print the first few rows of a DataFrame

(b) To sort a DataFrame by a specific column

(c) To calculate summary statistics for a DataFrame

(d) To remove rows from a DataFrame that contain missing values


8. What is the purpose of the fillna() function in Pandas?

(a) To print the first few rows of a DataFrame

(b) To sort a DataFrame by a specific column

(c) To calculate summary statistics for a DataFrame

(d) To replace missing values in a DataFrame


9. What is the output of the following python pandas code?

import pandas as pd

data = {'Name': ['Sunit', 'Bob', 'Amit'], 'Age': [32, 25, 27]}
df = pd.DataFrame(data)

print(df['Age'].mean())


(a) 32

(b) 28.0

(c) 25

(d) 27


10. How do you access a specific column in a pandas DataFrame?

(a) df[column_name]

(b) df.column_name

(c) df.get_column(column_name)

(d) df['column_name']



Python Pandas MCQs Answers:

1. (a) To perform data analysis and manipulation

2. (d) All of the above

3. (c) 32

4. (d) Numpy ndarray

5. (a) To print the first few rows of a DataFrame

6. (d) To print the last few rows of a DataFrame

7. (d) To remove rows from a DataFrame that contain missing values

8. (d) To replace missing values in a DataFrame

9. (b) 28.0

10.(d) df['column_name']

 

Back to Python MCQs >

No comments:

Post a Comment