Skip to content

Commit 3c203f6

Browse files
committed
DOC: groupby.rst edits
1 parent c59b217 commit 3c203f6

File tree

2 files changed

+8
-11
lines changed

2 files changed

+8
-11
lines changed

doc/source/groupby.rst

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -822,8 +822,6 @@ that could be potential groupers.
822822
df.groupby([pd.Grouper(freq='6M',level='Date'),'Buyer']).sum()
823823
824824
825-
.. _groupby.nth:
826-
827825
Taking the first rows of each group
828826
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
829827

@@ -854,6 +852,8 @@ This shows the first or last n rows from each group.
854852
1 0 1 2
855853
5 2 5 6
856854
855+
.. _groupby.nth:
856+
857857
Taking the nth row of each group
858858
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
859859

@@ -864,24 +864,21 @@ To select from a DataFrame or Series the nth item, use the nth method. This is a
864864
df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B'])
865865
g = df.groupby('A')
866866
867-
# nth(0) is the same as g.first()
868867
g.nth(0)
869-
g.first()
870-
871-
# nth(-1) is the same as g.last()
872868
g.nth(-1)
873-
g.last()
874-
875-
# return the nth item
876869
g.nth(1)
877870
878871
If you want to select the nth not-null method, use the ``dropna`` kwarg. For a DataFrame this should be either ``'any'`` or ``'all'`` just like you would pass to dropna, for a Series this just needs to be truthy.
879872

880873
.. ipython:: python
881874
875+
# nth(0) is the same as g.first()
882876
g.nth(0, dropna='any')
877+
g.first()
883878
879+
# nth(-1) is the same as g.last()
884880
g.nth(1, dropna='any') # NaNs denote group exhausted when using dropna
881+
g.last()
885882
886883
g.B.nth(0, dropna=True)
887884

doc/source/v0.14.0.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,10 @@ More consistent behaviour for some groupby methods:
230230

231231
df = DataFrame([[1, np.nan], [1, 4], [5, 6]], columns=['A', 'B'])
232232
g = df.groupby('A')
233-
g.nth(0) # can also use negative ints
233+
g.nth(0)
234234

235235
# this is equivalent to g.first()
236-
g.nth(0, dropna='any') # similar to old behaviour
236+
g.nth(0, dropna='any')
237237

238238
# this is equivalent to g.last()
239239
g.nth(-1, dropna='any')

0 commit comments

Comments
 (0)