np.nan is not comparable to np.nan… directly.
np.nan == np.nan False
While
np.isnan(np.nan) True
Could also do
pd.isnull(np.nan) True
examples
Filters nothing because nothing is equal to np.nan
s = pd.Series([1., np.nan, 2.]) s[s != np.nan] 0 1.0 1 NaN 2 2.0 dtype: float64
Filters out the null
s = pd.Series([1., np.nan, 2.]) s[s.notnull()] 0 1.0 2 2.0 dtype: float64
Use odd comparison behavior to get what we want anyway. If np.nan != np.nan is True then
s = pd.Series([1., np.nan, 2.]) s[s == s] 0 1.0 2 2.0 dtype: float64
Just dropna
s = pd.Series([1., np.nan, 2.]) s.dropna() 0 1.0 2 2.0 dtype: float64
Related Posts:
- how to reset index pandas dataframe after dropna() pandas dataframe
- numpy array: IndexError: too many indices for array
- Python3 – ModuleNotFoundError: No module named ‘numpy’
- ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
- Reading an Excel file in python using pandas
- Selecting multiple columns in a Pandas dataframe
- Curve curvature in numpy
- Get statistics for each group (such as count, mean, etc) using pandas GroupBy?
- How can I prevent the TypeError: list indices must be integers, not tuple when copying a python list to a numpy array?
- Converting NumPy array into Python List structure?
- ValueError: Unknown label type: ‘continuous’
- How to fix IndexError: invalid index to scalar variable
- Convert pandas dataframe to NumPy array
- ImportError: Missing required dependencies [‘numpy’]
- Python Pandas – Missing required dependencies [‘numpy’] 1
- ‘DataFrame’ object has no attribute ‘sort’
- ‘DataFrame’ object has no attribute ‘sort’
- TypeError: cannot unpack non-iterable int objec
- ‘DataFrame’ object has no attribute ‘sort’
- What is dtype(‘O’), in pandas?
- What is dtype(‘O’), in pandas?
- TypeError: ‘DataFrame’ object is not callable
- ValueError: ‘object too deep for desired array’
- What does axis in pandas mean?
- How to take column-slices of dataframe in pandas
- ‘numpy.ndarray’ object has no attribute ‘index’
- Normalize data in pandas
- Python pandas – filter rows after groupby
- Creating a Pandas DataFrame from a Numpy array: How do I specify the index column and column headers?
- pandas create new column based on values from other columns / apply a function of multiple columns, row-wise
- Building multi-regression model throws error: `Pandas data cast to numpy dtype of object. Check input data with np.asarray(data).`
- Coalesce values from 2 columns into a single column in a pandas dataframe
- Concat DataFrame Reindexing only valid with uniquely valued Index objects
- Replacing Pandas or Numpy Nan with a None to use with MysqlDB
- Difference between data type ‘datetime64[ns]’ and ‘
- Merging two DataFrames
- Calculate weighted average using a pandas/dataframe
- vectorize conditional assignment in pandas dataframe
- how to sort pandas dataframe from one column
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- TypeError: only integer scalar arrays can be converted to a scalar index with 1D numpy indices array
- ImportError: DLL load failed: The specified module could not be found
- ImportError: DLL load failed: The specified module could not be found
- Is there a way to create multiline comments in Python?
- ‘pip’ is not recognized as an internal or external command
- Renaming column names in Pandas
- How to reset index in a pandas dataframe? [duplicate]
- What is the purpose of the word ‘self’?
- Python- Robot Framework Rebot Using List
- How to update/upgrade a package using pip?
- How can I remove a specific item from an array?
- Behaviour of increment and decrement operators in Python
- Convert bytes to a string
- Python vs Cpython
- How do I update\upgrade pip itself from inside my virtual environment?
- Python integer incrementing with ++ [duplicate]
- Replacing instances of a character in a string
- Changing one character in a string
- What is the use of “assert” in Python?
- How can I represent an ‘Enum’ in Python?
- Delete a column from a Pandas DataFrame
- IndexError: too many indices for array
- IndexError: too many indices for array
- Import Error: No module named numpy
- How to deal with SettingWithCopyWarning in Pandas
- How to deal with SettingWithCopyWarning in Pandas
- How do I specify new lines on Python, when writing on files?
- What is the purpose of the return statement?
- Constructing pandas DataFrame from values in variables gives “ValueError: If using all scalar values, you must pass an index”
- How to iterate over rows in a DataFrame in Pandas
- pandas read_json: “If using all scalar values, you must pass an index”
- How to iterate over rows in a DataFrame in Pandas
- Relative imports – ModuleNotFoundError: No module named x
- bash: pip: command not found
- What is the difference between importing matplotlib and matplotlib.pyplot?
- Using global variables in a function
- How do I check what version of Python is running my script?
- ValueError: setting an array element with a sequence
- How to read a large file – line by line?
- Writing a pandas DataFrame to CSV file
- How to uninstall pip on OSX?
- How to delete a file or folder in Python?
- Converting integer to string in Python
- deleting file if it exists; python
- Reverse a string in Python
- Why am I seeing “TypeError: string indices must be integers”?
- Python for-in loop preceded by a variable
- Python Linked List
- What is the result of % in Python?
- How do I upgrade the Python installation in Windows 10?
- What does if __name__ == “__main__”: do?
- How to print without a newline or space
- Python’s equivalent of && (logical-and) in an if-statement
- Difference between del, remove, and pop on lists
- Python time.sleep() vs event.wait()
- Program to Unjumble Words on Python [closed]
- TypeError: ‘module’ object is not callable
- “inconsistent use of tabs and spaces in indentation”
- How can I install packages using pip according to the requirements.txt file from a local directory?
- Error: ‘int’ object is not subscriptable – Python