how do I calculate a rolling idxmax
<p>consider the <code>pd.Series</code> <code>s</code></p>

<pre><code>import pandas as pd
import numpy as np

np.random.seed([3,1415])
s = pd.Series(np.random.randint(0, 10, 10), list('abcdefghij'))
s

a    0
b    2
c    7
d    3
e    8
f    7
g    0
h    6
i    8
j    6
dtype: int64
</code></pre>

<p>I want to get the index for the max value for the rolling window of 3</p>

<pre><code>s.rolling(3).max()

a    NaN
b    NaN
c    7.0
d    7.0
e    8.0
f    8.0
g    8.0
h    7.0
i    8.0
j    8.0
dtype: float64
</code></pre>

<p>What I want is</p>

<pre><code>a    None
b    None
c       c
d       c
e       e
f       e
g       e
h       f
i       i
j       i
dtype: object
</code></pre>

<p>What I've done</p>

<pre><code>s.rolling(3).apply(np.argmax)

a    NaN
b    NaN
c    2.0
d    1.0
e    2.0
f    1.0
g    0.0
h    0.0
i    2.0
j    1.0
dtype: float64
</code></pre>

<p>which is obviously not what I want</p>

<p>I used a generator</p>

<pre><code>def idxmax(s, w):
    i = 0
    while i + w &lt;= len(s):
        yield(s.iloc[i:i+w].idxmax())
        i += 1

pd.Series(idxmax(s, 3), s.index[2:])

c    c
d    c
e    e
f    e
g    e
h    f
i    i
j    i
dtype: object
</code></pre>

python pandas numpy dataframe series