Informatics Practices
Write code that just produces single True/False as a result for the presence of missing values in whole DataFrame namely df.
Answer
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
Related Questions
Take a DataFrame of your choice. Write a program to calculate count of values only in a selective column.
Give two identical DataFrames Sales16 and Sales17. But Sales17 has some values missing. Write code so that Sales17 fills its missing values from the corresponding entries of Sales16.
Four Series objects Temp1, Temp2, Temp3 and Temp4 store the temperatures of week1, week2, week3 and week4 respectively. Create a DataFrame from these four series objects where the indexes should be 'Sunday', 'Monday', … , 'Saturday', and columns should be 'Week1', 'Week2', 'Week3' and 'week4'.
Given a DataFrame that stores the details of past 25 years' monthly sales. Some old data is however missing. Write a script to calculate average :
Monthly sales across years
Yearly sales
Make sure that missing values do not hamper the overall result.