Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

add .head() and .tail() to Series #296

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+14 −0
Split
View
@@ -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
@@ -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