Sunday 24 March 2024

Pandas DataFrame MCQs with Answers

 

Python Programming MCQs

Pandas DataFrame


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


1. Which of the following statements accurately describes a DataFrame?

a) A one-dimensional labeled array-like object

b) A multi-dimensional labeled data structure with potentially different data types in each column

c) A collection of Series objects with the same index

d) A specialized dictionary for storing numerical data

2. How do you create a DataFrame from a Python dictionary?

a) df = pd.Series(data)

b) df = pd.DataFrame(dict, index=index_list)

c) df = pd.Array.from_dict(data)

d) df = pd.Dict(data)

3. To access a specific column in a DataFrame, you would use:

a) df.get('column_name')

b) df['column_name']

c) df.column_name

d) df.at['column_name']

4. How can you filter rows in a DataFrame based on a condition?

a) df.filter(condition)

b) df.where(condition)

c) df[condition]

d) df.query(condition)

5. What function would you use to display the summary statistics of a DataFrame's numerical columns?

a) df.head()

b) df.info()

c) df.describe()

d) df.summary()

6. Which function removes missing values (NaN) from a DataFrame?

a) df.fillna(value)

b) df.replace(NaN, value)

c) df.dropna()

d) df.clean()

7. How can you replace missing values (NaN) with a specific value?

a) df.fillna(value)

b) df.replace(NaN, value)

c) df.clean_null(value)  # Not a standard method

d) df.set_null(value)

8. Which function is used to import the pandas library?

a) import numpy as pd

b) import pandas as pd 

c) from pandas import df

d) include pandas

9. How can you create a DataFrame from a CSV file?

a) df = pd.read_csv('data.csv')

b) df = pd.DataFrame.from_csv('data.csv')

c) df = open('data.csv')  # Incorrect approach

d) df = pd.parse_csv('data.csv')

10. Which of the following function can be used to delete a DataFrame column with missing value?

a) df.dropna(axis='columns')

b) df.delete()

c) df.dromna(axis='rows')

d) df.dropna(axis='dataframe')




ANSWERS: Python Pandas DataFrame MCQs:

1. b) A multi-dimensional labeled data structure with potentially different data types in each column

2. b) df = pd.DataFrame(dict, index=index_list)

3. b) df['column_name']

4. c) df[condition]

5. c) df.describe()

6. c) df.dropna()

7. a) df.fillna(value)

8. b) import pandas as pd 

9. a) df = pd.read_csv('data.csv')

10. a) df.dropna(axis='columns')

 

Back to Python MCQs >

No comments:

Post a Comment