Pandas quantiles in a series containing infinity?

I have the following framework:

calc_value 0 NaN 1 0.000000 2 0.100000 3 0.500000 4 2.333333 5 inf 

Now I want to calculate some quantiles:

 print df.quantile(.1)['calc_value'] print df.quantile(.25)['calc_value'] print df.quantile(.5)['calc_value'] print df.quantile(.75)['calc_value'] print df.quantile(.9)['calc_value'] 

But this returns:

 0.04 0.1 0.5 nan inf 

I do not understand why the 75th quantile works this way. Isn't that infinity?

+5
source share
1 answer

I think this might be a numpy bug:

 np.percentile([0,1,np.inf], 50) Out[63]: nan 

a

 np.median([0, 1, np.inf]) Out[65]: 1.0 

Instead of just taking a value at index 1, it takes values ​​at indexes 1 and 2 with weights 1 and 0. Thus, this results in 0 * inf .


In your case, the result should be 2.33 (try, for example, df.iloc[5,0] = 1e10 ).

0
source

Source: https://habr.com/ru/post/1246935/


All Articles