How to rewrite pandas.rolling().rank(method='average')

101 Views Asked by At

I have to rewrite Pandas to Spark. I have problem with this part of code:

#struct_ts is Spark DataFrame
#columns_to_take_pctile = <list of columns in str>
#period = 65 (days) / 130 / 260 / ....

grp = struct_ts.groupby(["struct", "otm_type"])

percentile = grp[columns_to_take_pctile].rolling(period).rank(method='average') / period

know that there is percent_rank() but it can be use when i want to calculate last 65/130/260.. (days) and want use rowsBetween/rangeBetween. Have anyone an idea how to resolve this problem ? Thanks for help.

1

There are 1 best solutions below

0
On

Below link show the problem which is similar.

[https://stackoverflow.com/questions/55958922/how-to-find-the-2nd-biggest-value-in-when-using-a-pyspark-window][1]