CBSE Class 12 Informatics Practices Question 97 of 101

Python Pandas — II — Question 6

Back to all questions
6
Question

Question 6

Write code that just produces single True/False as a result for the presence of missing values in whole DataFrame namely df.

Solution
import pandas as pd
data = {'A': [1, 2, None, 4], 'B': [None, 5, 6, 7], 'C': [8, 9, 10, 11]}
df = pd.DataFrame(data)
has_missing_values = False

for column in df.columns:
    for value in df[column]:
        if pd.isnull(value):
            has_missing_values = True
            break
print(has_missing_values)
Output
True
Answer