File tree 2 files changed +41
-1
lines changed
2 files changed +41
-1
lines changed Original file line number Diff line number Diff line change @@ -4652,14 +4652,17 @@ def head(self: FrameOrSeries, n: int = 5) -> FrameOrSeries:
4652
4652
on position. It is useful for quickly testing if your object
4653
4653
has the right type of data in it.
4654
4654
4655
+ For negative values of `n`, this function returns all rows except
4656
+ the last `n` rows, equivalent to ``df[:-n]``.
4657
+
4655
4658
Parameters
4656
4659
----------
4657
4660
n : int, default 5
4658
4661
Number of rows to select.
4659
4662
4660
4663
Returns
4661
4664
-------
4662
- obj_head : same type as caller
4665
+ same type as caller
4663
4666
The first `n` rows of the caller object.
4664
4667
4665
4668
See Also
@@ -4699,6 +4702,17 @@ def head(self: FrameOrSeries, n: int = 5) -> FrameOrSeries:
4699
4702
0 alligator
4700
4703
1 bee
4701
4704
2 falcon
4705
+
4706
+ For negative values of `n`
4707
+
4708
+ >>> df.head(-3)
4709
+ animal
4710
+ 0 alligator
4711
+ 1 bee
4712
+ 2 falcon
4713
+ 3 lion
4714
+ 4 monkey
4715
+ 5 parrot
4702
4716
"""
4703
4717
4704
4718
return self .iloc [:n ]
@@ -4711,6 +4725,9 @@ def tail(self: FrameOrSeries, n: int = 5) -> FrameOrSeries:
4711
4725
position. It is useful for quickly verifying data, for example,
4712
4726
after sorting or appending rows.
4713
4727
4728
+ For negative values of `n`, this function returns all rows except
4729
+ the first `n` rows, equivalent to ``df[n:]``.
4730
+
4714
4731
Parameters
4715
4732
----------
4716
4733
n : int, default 5
@@ -4758,6 +4775,17 @@ def tail(self: FrameOrSeries, n: int = 5) -> FrameOrSeries:
4758
4775
6 shark
4759
4776
7 whale
4760
4777
8 zebra
4778
+
4779
+ For negative values of `n`
4780
+
4781
+ >>> df.tail(-3)
4782
+ animal
4783
+ 3 lion
4784
+ 4 monkey
4785
+ 5 parrot
4786
+ 6 shark
4787
+ 7 whale
4788
+ 8 zebra
4761
4789
"""
4762
4790
4763
4791
if n == 0 :
Original file line number Diff line number Diff line change @@ -2377,6 +2377,8 @@ def head(self, n=5):
2377
2377
from the original DataFrame with original index and order preserved
2378
2378
(``as_index`` flag is ignored).
2379
2379
2380
+ Does not work for negative values of `n`.
2381
+
2380
2382
Returns
2381
2383
-------
2382
2384
Series or DataFrame
@@ -2390,6 +2392,10 @@ def head(self, n=5):
2390
2392
A B
2391
2393
0 1 2
2392
2394
2 5 6
2395
+ >>> df.groupby('A').head(-1)
2396
+ Empty DataFrame
2397
+ Columns: [A, B]
2398
+ Index: []
2393
2399
"""
2394
2400
self ._reset_group_selection ()
2395
2401
mask = self ._cumcount_array () < n
@@ -2405,6 +2411,8 @@ def tail(self, n=5):
2405
2411
from the original DataFrame with original index and order preserved
2406
2412
(``as_index`` flag is ignored).
2407
2413
2414
+ Does not work for negative values of `n`.
2415
+
2408
2416
Returns
2409
2417
-------
2410
2418
Series or DataFrame
@@ -2418,6 +2426,10 @@ def tail(self, n=5):
2418
2426
A B
2419
2427
1 a 2
2420
2428
3 b 2
2429
+ >>> df.groupby('A').tail(-1)
2430
+ Empty DataFrame
2431
+ Columns: [A, B]
2432
+ Index: []
2421
2433
"""
2422
2434
self ._reset_group_selection ()
2423
2435
mask = self ._cumcount_array (ascending = False ) < n
You can’t perform that action at this time.
0 commit comments