BUG: filter with a multi-grouping including a datetimelike fails · Issue #10114 · pandas-dev/pandas (original) (raw)
Navigation Menu
- Explore
- Pricing
Provide feedback
Saved searches
Use saved searches to filter your results more quickly
Appearance settings
Description
this was changed in #9921 (worked prior to 0.16.0)
cc @evanpw
so using a multiple grouper where one item is a datetimelike fails as the name in self.indices
fails. Instead .get_group()
can be used to fix
In [1]: df = DataFrame({'A' : np.arange(5), 'B' : ['foo','bar','foo','bar','bar'], 'C' : Timestamp('20130101') })
In [2]: df
Out[2]:
A B C
0 0 foo 2013-01-01
1 1 bar 2013-01-01
2 2 foo 2013-01-01
3 3 bar 2013-01-01
4 4 bar 2013-01-01
In [3]: df.groupby(['B','C']).filter(lambda x: True)
Out[3]:
Empty DataFrame
Columns: [A, B, C]
Index: []
In [4]: df.groupby(['B']).filter(lambda x: True)
Out[4]:
A B C
0 0 foo 2013-01-01
1 1 bar 2013-01-01
2 2 foo 2013-01-01
3 3 bar 2013-01-01
4 4 bar 2013-01-01
In [5]: df.groupby(['C']).filter(lambda x: True)
Out[5]:
A B C
0 0 foo 2013-01-01
1 1 bar 2013-01-01
2 2 foo 2013-01-01
3 3 bar 2013-01-01
4 4 bar 2013-01-01