I'm using Pandas to explore some datasets. I have this dataframe:
I want to exclude any row that has a value in column City
. So I've tried:
new_df = all_df[(all_df["City"] == "None") ]
new_df
But then I got an empty dataframe:
It works whenever I use any value other than None
. Any idea how to filter this dataframe?
Consider using isnull()
to locate missing values
all_df[all_df['City'].isnull()]
Try this to select only the None
values for city column:
new_df = all_df['City'][all_df['City'] == "None"]
Try this to see all other columns which has the same rows of 'City'==None
new_df = all_df[all_df['City'] == "None"]
print(new_df.head()) # with function head() you can see the first 5 rows
Another alternative is to use the query
method:
In [3]: all_df.query('City != City')
Out[3]:
FACTS_Value Region City Village
0 34135.0 Al Bahah None None
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With