How I can delete a specific variable names in Python?

71 views Asked by At

Here's the data:

id  date    age case_id country province    region  sex travel  travelh
1   1516    2020-03-23  40-49   1516    Canada  Ontario York    Male    1   Costa Rica
4   5658    2020-03-29  60-69   5657    Canada  Ontario Algoma  Female  1   United States
5   642 2020-03-18  Not Reported    642 Canada  Nova Scotia Not Reported    Not Reported    1   Not Reported
6   3560    2020-03-26  60-69   3560    Canada  Ontario Simcoe Muskoka  Male    1   India, United Arab Emirates
7   725 2020-03-18  80-89   725 Canada  Ontario Chatham-Kent    Female  1   United States

I wrote

df.dropna(inplace=True) 

but it did not work for all "Not Reported". Is there any ways to delete "not reported" rows in the dataset?

2

There are 2 answers

0
Abdul Moeez On

You can delete rows with Not Reported values in your dataset using the following code:

df = df[df != 'Not Reported'].dropna(how='any')
0
Stu Sztukowski On

Convert Not Reported to None

df = df.replace('Not Reported', None).dropna()