Handling Missing Data

This quiz on Handling Missing Data tests your knowledge of key methods and techniques used to identify, manage, and resolve missing values in datasets.

Last Updated :
Discuss
Comments

Question 1

Which method is used to fill missing values with the mean of a column in Pandas?

  • dropna()

  • fillna()

  • mean()

  • interpolate()

Question 2

What will be the output of the following code?

Python
import pandas as pd
import numpy as np
data = {'A': [1, 2, np.nan, 4], 'B': [np.nan, 2, 3, 4]}
df = pd.DataFrame(data)
result = df.isnull().sum()
print(result)


  • A 1

    B 1

    dtype: int64

  • A 2

    B 2

    dtype: int64

  • A 1

    B 2

    dtype: int64

  • A 2

    B 1

    dtype: int64


Question 3

Which of the following methods is suitable for forward-filling missing data in a DataFrame?

  • `fillna(method='ffill')`

  • `fillna(method='bfill')`

  • `interpolate()

  • `dropna()`

Question 4

What is the result of the following code?

Python
import pandas as pd
import numpy as np
data = {'A': [1, np.nan, 3], 'B': [4, 5, np.nan]}
df = pd.DataFrame(data)
df.dropna(axis=1, how='any', inplace=True)
print(df)


  • Empty DataFrame

  • A B

    0 1 4

  • A

    0 1

    2 3

  • Empty DataFrame

    Columns: []

    Index: [0, 1, 2]

Question 5

What does the interpolate() method do when handling missing values in Pandas?

  • Drops rows with missing values

  • Replaces missing values using a linear interpolation method

  • Fills missing values with a fixed value

  • None of the above

Question 6

What is the output of this code snippet?

Python
import pandas as pd
import numpy as np

data = {'A': [np.nan, 2, np.nan, 4], 'B': [1, np.nan, 3, 4]}
df = pd.DataFrame(data)
df['A'] = df['A'].fillna(df['A'].mean())
print(df)


  • A B

    0 3.0 1.0

    1 2.0 NaN

    2 3.0 3.0

    3 4.0 4.0

  • A B

    0 4.0 1.0

    1 2.0 NaN

    2 4.0 3.0

    3 4.0 4.0

  • A B

    0 NaN 1.0

    1 2.0 NaN

    2 NaN 3.0

    3 4.0 4.0

  • A B

    0 NaN NaN

    1 NaN NaN

    2 NaN NaN

    3 NaN NaN

Question 7

Which method permanently removes rows with missing values?

  • dropna()

  • fillna()

  • isnull()

  • notnull()

Question 8

In the following code, how many rows will remain after execution?

Python
import pandas as pd
import numpy as np

data = {'A': [1, np.nan, 3], 'B': [4, np.nan, np.nan]}
df = pd.DataFrame(data)
df.dropna(how='all', inplace=True)


  • 0

  • 1

  • 3

  • 2

Question 9

What will the following code output?

Python
import pandas as pd
import numpy as np

data = {'A': [np.nan, 2, 3], 'B': [4, np.nan, 6]}
df = pd.DataFrame(data)
df.fillna({'A': 0, 'B': 1}, inplace=True)
print(df)


  • A B

    0 0.0 4.0

    1 2.0 1.0

    2 3.0 6.0

  • A B

    0 NaN 4.0

    1 2.0 NaN

    2 3.0 6.0

  • A B

    0 NaN 1.0

    1 2.0 1.0

    2 3.0 6.0

  • A B

    0 0.0 1.0

    1 2.0 1.0

    2 3.0 6.0

Question 10

Which of the following is true about dropna(subset=[columns])?

  • Removes all rows with missing values across the specified subset of columns

  • Removes rows only if all specified columns have missing values

  • Removes rows only if no columns in the subset have missing values

  • None of the above

Tags:

There are 10 questions to complete.

Take a part in the ongoing discussion