numpy 1.9.0 has the function nanmedian:

nanmedian(a, axis=None, out=None, overwrite_input=False, keepdims=False)
    Compute the median along the specified axis, while ignoring NaNs.

    Returns the median of the array elements.

    .. versionadded:: 1.9.0

E.g.

>>> from numpy import nanmedian, NaN
>>> nanmedian([1,2,3,NaN,NaN,NaN,NaN,NaN,NaN])
2.0

If you can't use version 1.9.0 of numpy, something like @Parker's answer will work; e.g.

>>> import numpy as np
>>> x = np.array([1,2,3,NaN,NaN,NaN,NaN,NaN,NaN])
>>> np.median(x[~np.isnan(x)])
2.0

or

>>> np.median(x[np.isfinite(x)])
2.0

(When applied to a boolean array, ~ is the unary operator notation for not.)

Answer from Warren Weckesser on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.nanmedian.html
numpy.nanmedian — NumPy v2.4 Manual
January 31, 2021 - Compute the median along the specified axis, while ignoring NaNs.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-numpy-nanmedian-function
Python | Numpy nanmedian() function - GeeksforGeeks
June 20, 2022 - numpy.nanmedian() function can be used to calculate the median of array ignoring the NaN value. If array have NaN value and we can find out the median without effect of NaN value.
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_median.htm
NumPy - Median
You can use the numpy.nanmedian() function, which computes the median while ignoring NaN values.
🌐
Vultr Docs
docs.vultr.com › python › third-party › numpy › median
Python Numpy median() - Calculate Median Value | Vultr Docs
November 15, 2024 - Here, nanmedian() calculates the median while ignoring the NaN value. The output median of the array without the NaN value is 4.0. The numpy.median() function is a fundamental tool for statistical analysis in Python, especially useful in robustly ...
Find elsewhere
🌐
Data Science Parichay
datascienceparichay.com › home › blog › median of numpy array with nan values
Median of Numpy Array with NaN Values - Data Science Parichay
July 6, 2022 - # median of array with nan values numpy.nanmedian(ar) It returns the median value in the array ignoring all the NaN values.
🌐
JAX Documentation
docs.jax.dev › en › latest › _autosummary › jax.numpy.nanmedian.html
jax.numpy.nanmedian — JAX documentation
Return the median of array elements along a given axis, ignoring NaNs. JAX implementation of numpy.nanmedian().
🌐
Python
bugs.python.org › issue33084
Issue 33084: statistics module: NaN handling in median, median_high an median_low - Python tracker
This issue tracker has been migrated to GitHub, and is currently read-only. For more information, see the GitHub FAQs in the Python's Developer Guide · This issue has been migrated to GitHub: https://github.com/python/cpython/issues/77265
🌐
Astropy
docs.astropy.org › en › stable › api › astropy.stats.mad_std.html
mad_std — Astropy v7.2.0
The function used to compute the median. Defaults to numpy.ma.median for masked arrays, otherwise to numpy.median. ... Ignore NaN values (treat them as if they are not in the array) when computing the median.
🌐
Pythontutorials
pythontutorials.net › blog › numpy-nanmedian
Mastering `numpy.nanmedian`: A Comprehensive Guide | PythonTutorials.net
July 3, 2025 - One such function is `numpy.nanmedian`, which computes the median of an array while ignoring `NaN` (Not a Number) values. This blog post aims to provide a comprehensive understanding of `numpy.nanmedian`, including its fundamental concepts, usage methods, common practices, and best practices.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › numpy nanmean() – get mean ignoring nan values
NumPy nanmean() - Get Mean ignoring NAN Values - Spark By {Examples}
March 27, 2024 - In this article, I have explained how to use the NumPy nanmean() function in Python which calculates the arithmetic mean/average of the array along a specified axis while ignoring NaN (Not a Number) values with examples.
🌐
Python Guides
pythonguides.com › python-numpy-median
Python NumPy Median() Function With Examples
March 19, 2023 - Free Python, Machine Learning & Web Dev tutorials for all skill levels. 1,000+ tutorials, free course, free PDF & tools. Start learning today at Python Guides.
🌐
Stack Overflow
stackoverflow.com › questions › 73548669 › when-finding-the-median-in-a-table-how-do-i-specify-to-ignore-nan-values
numpy - When finding the median in a table, how do I specify to ignore NaN values? - Stack Overflow
I am trying to find the median of a table without it considering the NaN values in the table. Is there a simple way to have the function ignore those values? INPUT data_source = (r"C:\Users\m...
🌐
Codecademy
codecademy.com › article › hands-on-statistics-with-numpy-in-python
Hands-on Statistics with NumPy in Python | Codecademy
95. nan 72. 99.] The median value is: nan · To ignore the nan values and calculate the median for the rest of the values in the array, we can use the nanmedian() function, as shown below:
🌐
MathWorks
mathworks.com › statistics and machine learning toolbox › descriptive statistics and visualization › descriptive statistics
nanmedian - (Not recommended) Median, ignoring NaN values - MATLAB
For vectors x, nanmedian(x) is the median of the remaining elements, once NaN values are removed. For matrices X, nanmedian(X) is a row vector of column medians, once NaN values are removed.