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
- ImportError: DLL load failed: The specified module could not be found
- Python- Robot Framework Rebot Using List
- Relative imports – ModuleNotFoundError: No module named x
- Using global variables in a function
- How do I upgrade the Python installation in Windows 10?
- Python Variable Declaration
- Writing a pandas DataFrame to CSV file
- How do I install pip on macOS or OS X?
- What is the necessity of plt.figure() in matplotlib?
- Pandas DataFrame Groupby two columns and get counts
- How to fix ‘Object arrays cannot be loaded when allow_pickle=False’ for imdb.load_data() function?
- Most efficient way to find mode in numpy array
- How to show all columns’ names on a large pandas dataframe?
- How to groupby based on two columns in pandas?
- How to deal with SettingWithCopyWarning in Pandas
- ImportError: No module named pandas
- data type not understood
- Creating an empty Pandas DataFrame, then filling it?
- DataFrame constructor not properly called
- How to iterate over rows in a DataFrame in Pandas
- TypeError: ‘numpy.float64’ object is not callable
- Convert a tensor to numpy array in Tensorflow?
- pandas: merge (join) two data frames on multiple columns
- TypeError: ‘numpy.float64’ object is not callable?
- Why do I get: “Length of values does not match length of index” error?
- why should I make a copy of a data frame in pandas
- How to normalize a NumPy array to a unit vector?
- Pandas, merging two dataframes on multiple columns, and multiplying result
- How to customize a scatter matrix to see all titles?
- How can I upgrade NumPy?
- How to get element-wise matrix multiplication (Hadamard product) in numpy?
- ValueError: could not broadcast input array from shape (224,224,3) into shape (224,224)
- Overflow Error in Python’s numpy.exp function
- Pytorch tensor to numpy array
- ‘numpy.float64’ object is not iterable
- Can’t broadcast input array from shape (3,1) into shape (3,)
- deleting rows in numpy array
- Count unique values using pandas groupby
- Ignoring NaNs with str.containsv
- No numeric types to aggregate – change in groupby() behaviour?
- Solution for SpecificationError: nested renamer is not supported while agg() along with groupby()
- Pandas split DataFrame by column value
- Using numpy to build an array of all combinations of two arrays
- Can’t update to numpy 1.13 with anaconda?
- TypeError: only integer arrays with one element can be converted to an index 3
- Numpy, multiply array with scalar
- Python 3: Multiply a vector by a matrix without NumPy
- datetime to string with series in pandas
- How to add a new row to an empty numpy array
- pandas groupby sort within groups
- if else function in pandas dataframe
- Read data (.dat file) with Pandas
- Is there any numpy group by function?
- Boolean Series key will be reindexed to match DataFrame index
- Mean Squared Error in Numpy?
- Is there a head and tail method for Numpy array?
- pandas: multiple conditions while indexing data frame – unexpected behavior
- Logical operators for Boolean indexing in Pandas
- Transposing a 1D NumPy array
- numpy.float64 object is not iterable…but I’m NOT trying to
- How to update Pandas from Anaconda and is it possible to use eclipse with this last
- Compare two columns using pandas