nth
doesn't inlcude group key as the same as first
and last
.
df = pd.DataFrame({'A': [1, 2, 3, 4, 5], 'B': [1, 2, 3, 4, 5],
'G': [1, 1, 2, 2, 1]})
g = df.groupby('G')
g.nth(1)
# A B
# G
#1 2 2
#2 4 4
However, calling head
makes the behavior change. Looks to be caused by _set_selection_from_grouper
caches its selection.
g = df.groupby('G')
g.head()
g.nth(1)
# A B G
# G
#1 2 2 1
#2 4 4 2
Expected Output
always as below.
g.nth(1)
# A B
# G
#1 2 2
#2 4 4
output of pd.show_versions()
current master.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4