Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: pydata/pandas
...
head fork: hammer/pandas
compare: master
Checking mergeability… Don't worry, you can still create the pull request.
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 26, 2011
Jeff Hammerbacher ENH: add .head() and .tail() to Series 7d7d210
Showing with 14 additions and 0 deletions.
  1. +10 −0 pandas/core/series.py
  2. +4 −0 pandas/tests/test_series.py
View
10 pandas/core/series.py
@@ -553,6 +553,16 @@ def get(self, key, default=None):
else:
return default
+ def head(self, n=5):
+ """Returns first n rows of Series
+ """
+ return self[:n]
+
+ def tail(self, n=5):
+ """Returns last n rows of Series
+ """
+ return self[-n:]
+
#----------------------------------------------------------------------
# Statistics, overridden ndarray methods
View
4 pandas/tests/test_series.py
@@ -1244,6 +1244,10 @@ def test_unstack(self):
unstacked = s.unstack(0)
assert_frame_equal(unstacked, expected)
+ def test_head_tail(self):
+ assert_frame_equal(self.series.head(), self.series[:5])
+ assert_frame_equal(self.series.tail(), self.series[-5:])
+
#-------------------------------------------------------------------------------
# TimeSeries-specific

No commit comments for this range

Something went wrong with that request. Please try again.