Getting the last value for each week, with the matching date
<p>So I start out with a <code>pd.Series</code> called <code>jpm</code>, and I would like to group it into weeks and take the last value from each week. This works with the code below, it does get the last value. But it changes corresponding index to the Sunday of the week, and I would like it to <strong>leave it unchaged</strong>.</p>

<pre><code>import pandas_datareader.data as web
import pandas as pd

start = pd.datetime(2015, 11, 1)
end = pd.datetime(2015, 11, 17)

raw_jpm = web.DataReader("JPM", 'yahoo', start, end)["Adj Close"]
jpm = raw_jpm.ix[raw_jpm.index[::2]]
</code></pre>

<p><code>jpm</code> is now</p>

<pre><code>Date
2015-11-02    64.125610
2015-11-04    64.428918
2015-11-06    66.982593
2015-11-10    66.219427
2015-11-12    64.575682
2015-11-16    65.074678
Name: Adj Close, dtype: float64
</code></pre>

<p>I want to do some operations to it, such as</p>

<pre><code>weekly = jpm.groupby(pd.TimeGrouper('W')).last()
</code></pre>

<p><code>weekly</code> is now</p>

<pre><code>Date
2015-11-08    66.982593
2015-11-15    64.575682
2015-11-22    65.074678
Freq: W-SUN, Name: Adj Close, dtype: float64
</code></pre>

<p>which is great, except all my dates got changed. The output I want, is:</p>

<pre><code>Date
2015-11-06    66.982593
2015-11-12    64.575682
2015-11-16    65.074678
</code></pre>

<p>you can do it this way:</p>

<pre><code>In [15]: jpm
Out[15]:
Date
2015-11-02    64.125610
2015-11-04    64.428918
2015-11-06    66.982593
2015-11-10    66.219427
2015-11-12    64.575682
2015-11-16    65.074678
Name: Adj Close, dtype: float64

In [16]: jpm.groupby(jpm.index.week).transform('last').drop_duplicates(keep='last')
Out[16]:
Date
2015-11-06    66.982593
2015-11-12    64.575682
2015-11-16    65.074678
dtype: float64
</code></pre>

<p>Explanation:</p>

<pre><code>In [17]: jpm.groupby(jpm.index.week).transform('last')
Out[17]:
Date
2015-11-02    66.982593
2015-11-04    66.982593
2015-11-06    66.982593
2015-11-10    64.575682
2015-11-12    64.575682
2015-11-16    65.074678
dtype: float64
</code></pre>

python pandas