Let's say we have:
import pandas as pd
df = pd.DataFrame([[1, 2], [4, None], [None, 7]], dtype=object, columns=['a', 'b'])
print(df['a'])
# 0 1
# 1 4
# 2 None
I have read Python Pandas Dataframe, remove all rows where 'None' is the value in any column and Pandas - Filtering None Values, and I do know that the solution to remove rows with None
is to filter the dataframe with df[~df['a'].isnull()]
, since we have:
df['a'].isnull()
# 0 False
# 1 False
# 2 True
Question: why don't these two pythonic-looking solutions fail?
df[df['a'] != None] # fails: filters nothing
df[df['a'] is not None] # fails too