Home > Blockchain >  When finding the median in a table, how do I specify to ignore NaN values?
When finding the median in a table, how do I specify to ignore NaN values?

Time:09-01

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\mburen\Desktop\TestPython2.xlsx")
bk = pd.read_excel(data_source)
print("Here is what the original excel table looks like. The bk table.")
print (bk)
print ()

#now for finding the median
x=np.median(bk)
print (x)

OUTPUT

Here is the table

The median is the calculated central number of all the values. The median is: nan

CodePudding user response:

Did you see np.nanmedian introduced in numpy 1.9? nanmedian

  • Related