-4

I have a DataFrame df. This dataframe has 1000 rows and 20 columns. Rows are dates and 20 columns are different shares.

This is 1000 dates of stock prices from old to new (last row is todays price).

I want to calculate for each column, the percentile rank of todays price (last element in a column), against the full history of that particular column. So for example the first value of our output would be the final value in column (1) percentranked against all the values in column (1) and so on.

So the output would be just 20 values of 20xpercentage ranks of todays price against the history of the entire stock.

Alex K
  • 8,269
  • 9
  • 39
  • 57
Mohit
  • 3
  • 3

1 Answers1

1

Tough to tell what you're looking for in terms of output, but this would give you a 1x20 DataFrame where the only row in the index is the latest day and the values in each column are the percentage rank of each column versus the full history of that particular column. Assuming you have a 1000 x 20 DataFrame sorted in oldest to newest...

data.rank().tail(1).div(len(data))
AP228
  • 333
  • 1
  • 3
  • 6