Delete a Row with Date Missing Value using Pandas Python

Abhishek is going to manage the event data. He is having the data as dataframe, and his manager doesn’t want to store the data whose function date is not be decided, so he requested to Abhishek to delete the row for those customers who are not yet decided for their function date.
So help Abhishek to delete the customers who are not giving their function dates.

Delete a Row with Date Missing Value using Pandas

dropna(): https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.dropna.html

The following is the 2D format for the dataframe:  
customer_name, address, date, eventType, cost, noOfPeople
Here eventType is described as marriage, get together, and mehndi. 

Filled the data in the dataframe as the CSV file, in the above format.

Input Format:
For a sample data frame, see the attached CSV file.

Output Format:
The output is the dataframe after deleting the row where the date is missing.

Sample Input:
See the attached CSV file.

Sample Output:
cust_name    addr        date event_type   cost  no_of_people
  Vikram  Hebbal  08/20/2018   marriage  40000           400
  Sachin  Indore  04/14/2019     mehndi  75000           700
  Ankita   Delhi  08/24/2019     mehndi  85000           850

Description of the Sample Input/Output 1:
Sample Dataframe: 

cust_name,addr,date,event_type,cost,no_of_people
Vikram,Hebbal,08/20/2018,marriage,40000,400
Sachin,Indore,04/14/2019,mehndi,75000,700
Amit,Bhopal,,marriage,20000,600
Ankita,Delhi,08/24/2019,mehndi,85000,850

The third row having NaN in date column, so we have to delete the customer Amit, so following is the final dataframe:
cust_name    addr        date event_type   cost  no_of_people
  Vikram  Hebbal  08/20/2018   marriage  40000           400
  Sachin  Indore  04/14/2019     mehndi  75000           700
  Ankita   Delhi  08/24/2019     mehndi  85000           850

cust_name,addr,date,event_type,cost,no_of_people
Vikram,Hebbal,08/20/2018,marriage,40000,400
Sachin,Indore,04/14/2019,mehndi,75000,700
Amit,Bhopal,,marriage,20000,600
Ankita,Delhi,08/24/2019,mehndi,85000,850

Solution:

import pandas as pd

df = pd.read_csv('dataFrame1.csv')
print(df.dropna(subset=['date']))

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *