Panda rolling window percentile rank
Date : March 29 2020, 07:55 AM
Hope this helps Your lambda receives a numpy array, which does not have a .rank method — it is pandas's Series and DataFrame that have it. You can thus change it to pctrank = lambda x: pd.Series(x).rank(pct=True).iloc[1]
def pctrank(x):
n = len(x)
temp = x.argsort()
ranks = np.empty(n)
ranks[temp] = (np.arange(n) + 1) / n
return ranks[1]

Use quantile to get percentile in r
Tag : r , By : Chris Woods
Date : March 29 2020, 07:55 AM
I hope this helps . It's basically what the error says  In the second example, you are providing 2 groups (probs = c(.3,.7)), which is fewer than the amount of labels you provide (c("L","M","B")) Notice that in your first code snippet, seq(0,1 , by= 0.5) You generate 3 distinct values (0.0, 0.5, 1.0)

How to compute moving (or rolling, if you will) percentile/quantile for a 1d array in numpy?
Date : March 29 2020, 07:55 AM
wish of those help We could create the sliding windows with np.lib.stride_tricks.as_strided, implemented as a function as strided_app  In [14]: a = np.array([1, 5, 7, 2, 4, 6, 9, 3, 8, 10]) # input array
In [15]: W = 3 # window length
In [16]: np.percentile(strided_app(a, W,1), 50, axis=1)
Out[16]: array([ 5., 5., 4., 4., 6., 6., 8., 8.])
In [39]: np.pad(_, 1, 'constant', constant_values=(np.nan)) #_ is previous one
Out[39]: array([ nan, 5., 5., 4., 4., 6., 6., 8., 8., nan])

calculate percentile using rolling window pandas
Date : March 29 2020, 07:55 AM
it helps some times This is a bug, referenced in GH9413 and GH16211. The reason, as given by the devs  df.rolling(window=3, center=False).apply(lambda x: pd.Series(x).quantile(0.75))
0
0 NaN
1 NaN
2 2.5
3 2.5
4 2.5
5 2.5
6 2.5
7 2.5
8 2.5

when to use np.quantile and np.percentile?
Tag : python , By : user150744
Date : March 29 2020, 07:55 AM

