Im calculating percentiles and doing some operations along too many columns.
JavaScript
x
4
1
perc = np.percentile([100,100,100,100,100,100,100,200,300,123,124,90,98,999,567,345],[20,40,60,80])
2
print(perc)
3
array([100., 100., 123., 300.])
4
I need to get the unique values then, setting my vector i got this:
JavaScript
1
3
1
set(perc)
2
{100.0, 123.0, 300.0}
3
It works in almost all of the columns, but for any reason i got columns with this issue:
JavaScript
1
2
1
perc_1 = np.percentile([100,100,np.inf,np.inf,np.inf,np.inf,-np.inf,-np.inf,-np.inf],[20,40,60,80])
2
then calculating percentiles:
JavaScript
1
3
1
print(perc_1)
2
array([ nan, 100., nan, nan])
3
then, setting this vector i got this:
JavaScript
1
3
1
set(perc_1)
2
{nan, nan, 100.0, nan}
3
Setting doesnt work.
How can i solve this?
Advertisement
Answer
Since nan
values, which are float, are not equal even to themselves, you can use code below:
JavaScript
1
3
1
perc_1 = np.percentile([100,100,np.inf,np.inf,np.inf,np.inf,-np.inf,-np.inf,-np.inf],[20,40,60,80])
2
list(filter(lambda x: x==x, list(set(perc_1))))
3
Output
JavaScript
1
2
1
[100.0]
2