Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9176233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:04:07+00:00 2026-06-17T17:04:07+00:00

I am new to Python and the Pandas library, so apologies if this is

  • 0

I am new to Python and the Pandas library, so apologies if this is a trivial question. I am trying to rank a Timeseries over a rolling window of N days. I know there is a rank function but this function ranks the data over the entire timeseries. I don’t seem to be able to find a rolling rank function.
Here is an example of what I am trying to do:

           A

01-01-2013 100
02-01-2013 85
03-01-2013 110
04-01-2013 60
05-01-2013 20
06-01-2013 40

If I wanted to rank the data over a rolling window of 3 days, the answer should be:

           Ranked_A

01-01-2013 NaN
02-01-2013 Nan
03-01-2013 1
04-01-2013 3
05-01-2013 3
06-01-2013 2

Is there a built-in function in Python that can do this? Any suggestion?
Many thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T17:04:08+00:00Added an answer on June 17, 2026 at 5:04 pm

    If you want to use the Pandas built-in rank method (with some additional semantics, such as the ascending option), you can create a simple function wrapper for it

    def rank(array):
        s = pd.Series(array)
        return s.rank(ascending=False)[len(s)-1]
    

    that can then be used as a custom rolling-window function.

    pd.rolling_apply(df['A'], 3, rank)
    

    which outputs

    Date
    01-01-2013   NaN
    02-01-2013   NaN
    03-01-2013     1
    04-01-2013     3
    05-01-2013     3
    06-01-2013     2
    

    (I’m assuming the df data structure from Rutger’s answer)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

New to Python, have a simple, situational question: Trying to use BeautifulSoup to parse
Very new to python and can't understand why this isn't working. I have a
Brand new to Python (and programming in general), if this is simple and/or answered
Im new two python and am trying to grow a dictionary of dictionaries. I
New to pandas python. I have a dataframe (df) with two columns of cusips.
I am using a pandas/python dataframe. I am trying to do a lag subtraction.
This question is somewhat related to Visually separating bar chart clusters in pandas I
I am a new Python programmer and trying some stuff out. I want to
I'm working on a new Python authentication library for WSGI frameworks and want to
New to python and trying to learn the ropes of file i/o. Working with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.