<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# coding: utf-8
import pandas as pd
import numpy as np

frame = pd.read_csv(&quot;table.csv&quot;, engine=&quot;python&quot;, parse_dates=['since'])
print frame
d = pd.pivot_table(frame, index=pd.TimeGrouper(key='since', freq='1d'), values=[&quot;value&quot;], columns=['id'], aggfunc=np.sum, fill_value=0)
print d
print &quot;^that is not what I expected&quot;
frame = pd.read_csv(&quot;table2.csv&quot;, engine=&quot;python&quot;, parse_dates=['since'])  # add some values to a day
print frame
d = pd.pivot_table(frame, index=pd.TimeGrouper(key='since', freq='1d'), values=[&quot;value&quot;], columns=['id'], aggfunc=np.sum, fill_value=0)
print d"><pre class="notranslate"><span class="pl-c"># coding: utf-8</span>
<span class="pl-k">import</span> <span class="pl-s1">pandas</span> <span class="pl-k">as</span> <span class="pl-s1">pd</span>
<span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>

<span class="pl-s1">frame</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_csv</span>(<span class="pl-s">"table.csv"</span>, <span class="pl-s1">engine</span><span class="pl-c1">=</span><span class="pl-s">"python"</span>, <span class="pl-s1">parse_dates</span><span class="pl-c1">=</span>[<span class="pl-s">'since'</span>])
<span class="pl-k">print</span> <span class="pl-s1">frame</span>
<span class="pl-s1">d</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">pivot_table</span>(<span class="pl-s1">frame</span>, <span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-s1">pd</span>.<span class="pl-v">TimeGrouper</span>(<span class="pl-s1">key</span><span class="pl-c1">=</span><span class="pl-s">'since'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'1d'</span>), <span class="pl-s1">values</span><span class="pl-c1">=</span>[<span class="pl-s">"value"</span>], <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'id'</span>], <span class="pl-s1">aggfunc</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">sum</span>, <span class="pl-s1">fill_value</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)
<span class="pl-k">print</span> <span class="pl-s1">d</span>
<span class="pl-k">print</span> <span class="pl-s">"^that is not what I expected"</span>
<span class="pl-s1">frame</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">read_csv</span>(<span class="pl-s">"table2.csv"</span>, <span class="pl-s1">engine</span><span class="pl-c1">=</span><span class="pl-s">"python"</span>, <span class="pl-s1">parse_dates</span><span class="pl-c1">=</span>[<span class="pl-s">'since'</span>])  <span class="pl-c"># add some values to a day</span>
<span class="pl-k">print</span> <span class="pl-s1">frame</span>
<span class="pl-s1">d</span> <span class="pl-c1">=</span> <span class="pl-s1">pd</span>.<span class="pl-en">pivot_table</span>(<span class="pl-s1">frame</span>, <span class="pl-s1">index</span><span class="pl-c1">=</span><span class="pl-s1">pd</span>.<span class="pl-v">TimeGrouper</span>(<span class="pl-s1">key</span><span class="pl-c1">=</span><span class="pl-s">'since'</span>, <span class="pl-s1">freq</span><span class="pl-c1">=</span><span class="pl-s">'1d'</span>), <span class="pl-s1">values</span><span class="pl-c1">=</span>[<span class="pl-s">"value"</span>], <span class="pl-s1">columns</span><span class="pl-c1">=</span>[<span class="pl-s">'id'</span>], <span class="pl-s1">aggfunc</span><span class="pl-c1">=</span><span class="pl-s1">np</span>.<span class="pl-s1">sum</span>, <span class="pl-s1">fill_value</span><span class="pl-c1">=</span><span class="pl-c1">0</span>)
<span class="pl-k">print</span> <span class="pl-s1">d</span></pre></div>
<p dir="auto">The following data is the contents of <code class="notranslate">table.csv</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;id&quot;,&quot;since&quot;,&quot;value&quot;
&quot;81&quot;,&quot;2015-01-31 07:00:00+00:00&quot;,&quot;2200.0000&quot;
&quot;81&quot;,&quot;2015-02-01 07:00:00+00:00&quot;,&quot;2200.0000&quot;"><pre class="notranslate"><code class="notranslate">"id","since","value"
"81","2015-01-31 07:00:00+00:00","2200.0000"
"81","2015-02-01 07:00:00+00:00","2200.0000"
</code></pre></div>
<p dir="auto">This is <code class="notranslate">table2.csv</code>:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&quot;id&quot;,&quot;since&quot;,&quot;value&quot;
&quot;81&quot;,&quot;2015-01-31 07:00:00+00:00&quot;,&quot;2200.0000&quot;
&quot;81&quot;,&quot;2015-01-31 08:00:00+00:00&quot;,&quot;2200.0000&quot;
&quot;81&quot;,&quot;2015-01-31 09:00:00+00:00&quot;,&quot;2200.0000&quot;
&quot;81&quot;,&quot;2015-02-01 07:00:00+00:00&quot;,&quot;2200.0000&quot;"><pre class="notranslate"><code class="notranslate">"id","since","value"
"81","2015-01-31 07:00:00+00:00","2200.0000"
"81","2015-01-31 08:00:00+00:00","2200.0000"
"81","2015-01-31 09:00:00+00:00","2200.0000"
"81","2015-02-01 07:00:00+00:00","2200.0000"
</code></pre></div>
<p dir="auto">The output of print after pivoting <code class="notranslate">table.csv</code></p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="                                                                id  value
&lt;pandas.tseries.resample.TimeGrouper object at 0x7fc595f96c10&gt;  81   2200
id                                                              81   2200"><pre class="notranslate"><code class="notranslate">                                                                id  value
&lt;pandas.tseries.resample.TimeGrouper object at 0x7fc595f96c10&gt;  81   2200
id                                                              81   2200
</code></pre></div>
<p dir="auto">I would expect something like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="            value
id             81
since            
2015-01-31   2200
2015-02-01   2200"><pre class="notranslate"><code class="notranslate">            value
id             81
since            
2015-01-31   2200
2015-02-01   2200
</code></pre></div>
<p dir="auto">I can trace the problem to here:</p>
<p dir="auto"><a href="https://github.com/pydata/pandas/blob/62529cca28e9c8652ddf7cca3aa6d41d4e30bc0e/pandas/tools/pivot.py#L114">https://github.com/pydata/pandas/blob/62529cca28e9c8652ddf7cca3aa6d41d4e30bc0e/pandas/tools/pivot.py#L114</a> the index created by groupby already has the object there.</p>
<p dir="auto">I can't figure anything else. What is the problem, any fixes?</p>
<p dir="auto">Thanks.</p>
<p dir="auto">The following code seems to raise an error, since the result object does not make sense (well, at least to me):</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="In [61]: import datetime

In [62]: import pandas as pd

In [63]: df = pd.DataFrame.from_records ( [[datetime.datetime(2014,9,10),1234,&quot;start&quot;],
  [datetime.datetime(2013,10,10),1234,&quot;start&quot;]], columns = [&quot;date&quot;, &quot;change&quot;, &quot;event&quot;] )

In [64]: df
Out[64]: 
        date  change  event
0 2014-09-10    1234  start
1 2013-10-10    1234  start

In [65]: ts = df.set_index('date')

In [66]: ts
Out[66]: 
            change  event
date                     
2014-09-10    1234  start
2013-10-10    1234  start

In [67]: byperiod = ts.groupby([pd.TimeGrouper(freq=&quot;M&quot;), &quot;event&quot;], as_index=False)

In [68]: byperiod.groups
Out[68]: 
{&lt;pandas.tseries.resample.TimeGrouper at 0xab6bcaec&gt;: [Timestamp('2014-09-10 00:00:00')],
 'event': [Timestamp('2013-10-10 00:00:00')]}"><pre class="notranslate"><code class="notranslate">In [61]: import datetime

In [62]: import pandas as pd

In [63]: df = pd.DataFrame.from_records ( [[datetime.datetime(2014,9,10),1234,"start"],
  [datetime.datetime(2013,10,10),1234,"start"]], columns = ["date", "change", "event"] )

In [64]: df
Out[64]: 
        date  change  event
0 2014-09-10    1234  start
1 2013-10-10    1234  start

In [65]: ts = df.set_index('date')

In [66]: ts
Out[66]: 
            change  event
date                     
2014-09-10    1234  start
2013-10-10    1234  start

In [67]: byperiod = ts.groupby([pd.TimeGrouper(freq="M"), "event"], as_index=False)

In [68]: byperiod.groups
Out[68]: 
{&lt;pandas.tseries.resample.TimeGrouper at 0xab6bcaec&gt;: [Timestamp('2014-09-10 00:00:00')],
 'event': [Timestamp('2013-10-10 00:00:00')]}
</code></pre></div>
<p dir="auto">I would expect, for Out[68], two groups, one for each (date, event) pair.</p>
<p dir="auto">Am I wring, or this is a bug?</p>