BUG: groupby(.., as_index=False) with a TimeGrouper
See original GitHub issueHello,
I am doing some basic aggregation and boom, some weird bug occurs. Here is a reprex:
import pandas as pd
import numpy as np
idx2=[pd.to_datetime('2016-08-31 22:08:12.000') ,
pd.to_datetime('2016-08-31 22:09:12.200'),
pd.to_datetime('2016-08-31 22:20:12.400')]
test=pd.DataFrame({'quant':[1.0,1.0,3.0],
'quant2':[1.0,1.0,3.0],
'time2':[pd.to_datetime('2016-08-31 22:08:12.000') ,
pd.to_datetime('2016-08-31 22:09:12.200'),
pd.to_datetime('2016-08-31 22:20:12.400')]},
index=idx2)
test.reset_index(inplace = True)
test
Out[22]:
index quant quant2 time2
0 2016-08-31 22:08:12.000 1.0 1.0 2016-08-31 22:08:12.000
1 2016-08-31 22:09:12.200 1.0 1.0 2016-08-31 22:09:12.200
2 2016-08-31 22:20:12.400 3.0 3.0 2016-08-31 22:20:12.400
df= test.groupby(pd.Grouper(key='time2', freq='1T', closed = 'left', label = 'left'),as_index = False).agg(
{'quant' : 'sum',
'quant2' : 'sum'})
gives
File "<ipython-input-20-c09863316397>", line 19, in <module>
'quant2' : 'sum'})
File "C:\\Anaconda2\lib\site-packages\pandas\core\groupby.py", line 4036, in aggregate
return super(DataFrameGroupBy, self).aggregate(arg, *args, **kwargs)
File "C:\\Anaconda2\lib\site-packages\pandas\core\groupby.py", line 3491, in aggregate
self._insert_inaxis_grouper_inplace(result)
File "C:\\Anaconda2\lib\site-packages\pandas\core\groupby.py", line 4090, in _insert_inaxis_grouper_inplace
self.grouper.get_group_levels(),
File "C:\\Anaconda2\lib\site-packages\pandas\core\groupby.py", line 1911, in get_group_levels
if not self.compressed and len(self.groupings) == 1:
AttributeError: 'BinGrouper' object has no attribute 'compressed'
Is that expected? Why would the as_index = False
generate this error?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:3
- Comments:7 (4 by maintainers)
Top Results From Across the Web
pandas grouper issue with key that is an index - Stack Overflow
I think you need: pd.Grouper(level='Time',freq='15Min'). I believe you can add column Response to groupby , reshape by unstack and plot:
Read more >pandas.core.groupby.DataFrameGroupBy.resample
Provide resampling when using a TimeGrouper. Given a grouper, the function resamples it according to a string “string” -> “frequency”. See the frequency...
Read more >pandas - BUG : TimeGrouper가있는 groupby (.., as_index = False ...
기본 집계 및 붐을 수행 중이며 이상한 버그가 발생합니다. 다음은 reprex입니다. import pandas as pd import numpy ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
it’s been over 3 years since someone called dibs on this, but if you want a quick workaround, I was able to project the index col to its own column with a
.reset_index()
after the aggregation:@randomgambit : Thanks! Do you mind moving that code into your initial issue report? That will make it easier for us to read, even at just a glance.