Shivaraj a Business manager was maintaining an Event list consists of all the data w.r.t the event. At the time of Analysis he wanted to check is there any value missing in the dataset w.r.t whichever column data to be selected. So he wanted to know what are the data missing with respect to a particular column(Selected through the input) so that he can reconsider and fill it with the required data. Hence help him by building an application in such a way that on entering the column name present in the dataset should print “true” if the data is missing and should print “false” if the data present.
Missing Value using isnull()
NOTE:
Column name in the dataset should be as follows
(‘Sl No’,’EventName’,’EventManager’,’NoOfDates’,’StartDate’,’EndDate’,’HallName’,’HallAddress’,’HallPricePerDay’,’TotalCost’)
Input Format:
First line if the input consists of the number of rows present the dataset.
Next,n lines correspond to the data to be added to the dataset.
The last line of the input consists of a column name in which the missing value should be identified.
Output Format:
The output consists of the list of boolean values in which “true “represents the missing value and” false “represent cell has some value in it.
Print Invalid Input if the entered column name doesn’t exist in the data-frame.
Refer sample input-output for better understanding.
(All text in bold corresponds to the input and rest corresponds to output)
Sample Input-Output:
Enter number records
8
1 ,Marriage,krishnanand,2,12-08-2005,13-08-2005,krishna mansion,Krishna Mansion Krishnalaya Shringeri,60000,120000
2 ,Birthday Celebration,Akshay,1,14-08-2005,14-08-2005,Akshayalaya,Akshayalaya Akshaya Dama Yogendra Nagar Shimoga,35000,35000
3 ,House Warming,sunil,1,21-10-2005,21-10-2005,Sugamya Corner,Sugamya corner Vijaya nagar Mysore,50000,50000
4 ,Naming Ceremony,Surya,1,10-11-2005,10-11-2005,Suryodaya comforts,Suryodaya comforts Srirampura,20000,
5 ,Promossion Celebration,Aliya,1,15-11-2005,15-11-2005,Kabule convention hall,Kabule convention hall Bangalore,20000,20000
6 ,New Year Celebration,,2,31-12-2005,01-12-2005,Chinnaswammy stadium,Bangalore,,24000
7 ,Chrismas Celebration,Collin,2,24-12-2005,,Saint Philominas chruch,Saint Philominas chruch Mysore,25000,50000
8 ,Project outing,Santhosh,2,29-11-2005,30-11-2005,Mysore Palace Resort,Mysore Palace Resort Mysore,15000,30000
Enter Column name
TotalCost
0 False
1 False
2 False
3 True
4 False
5 False
6 False
7 False
Name: TotalCost, dtype: bool
Additional Sample TestCases
Sample Input and Output 1 :
Enter number records 4 1 ,Marraige,krishnanand,2,12-08-2005,13-08-2005,krishna mansion,Krishna Mansion Krishnalaya Shringeri,60000,120000 2 ,Birthday Celebration,Akshay,1,14-08-2005,14-08-2005,Akshayalaya,Akshayalaya Akshaya Dama Yogendra Nagar Shimoga,35000,35000 3 ,House Warming,sunil,1,21-10-2005,21-10-2005,Sugamya Corner,Sugamya corner Vijaya nagar Mysore,50000,50000 4 ,Naming Ceremony,Surya,1,10-11-2005,10-11-2005,Suryodaya comforts,Suryodaya comforts Srirampura,20000, Enter Column name HallCost Invalid Input
Sample Input and Output 2 :
Enter number records 5 1 ,Marr,krishnanand,2,12-08-2005,13-08-2005,krishna mansion,Krishna Mansion Krishnalaya Shringeri,60000,120000 2 ,Birthday Celebration,Akshay,1,14-08-2005,14-08-2005,Akshayalaya,Akshayalaya Akshaya Dama Yogendra Nagar Shimoga,35000,35000 3 ,House Warming,sunil,1,21-10-2005,21-10-2005,Sugamya Corner,Sugamya corner Vijaya nagar Mysore,50000,50000 4 ,Naming Ceremony,Surya,1,10-11-2005,10-11-2005,Suryodaya comforts,Suryodaya comforts Srirampura,20000, 7 ,Chrismas Celebration,Collin,2,24-12-2005,,Saint Philominas chruch,Saint Philominas chruch Mysore,25000,50000 Enter Column name EndDate Marr False Birthday Celebration False House Warming False Naming Ceremony False Chrismas Celebration True Name: EndDate, dtype: bool
Solution:
import numpy as np
import pandas as pd
n = int(input("Enter the number of books"))
df = pd.DataFrame(columns=['Sl No', 'EventName', 'EventManager', 'NoOfDates', 'StartDate', 'EndDate', 'HallName', 'HallAddress', 'HallPricePerDay', 'TotalCost'])
for i in range(n):
data = input().split(',')
df.loc[i] = data
col_num = input("\nEnter Column name\n")
if col_num not in df.columns:
print("Invalid Input")
else:
df=df.replace(r'^\s*$', np.nan, regex=True)
print(df[col_num].isnull())
Happy Learning – If you require any further information, feel free to contact me.