Skip to content

Commit 61e102a

Browse files
author
K.-Michael Aye
committed
adding left and right view to DataFrame, equivalent to head() and tail()
1 parent ad49095 commit 61e102a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

pandas/core/generic.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1781,7 +1781,7 @@ def head(self, n=5):
17811781
Returns first n rows
17821782
"""
17831783
l = len(self)
1784-
if l == 0 or n==0:
1784+
if l == 0 or n == 0:
17851785
return self
17861786
return self.iloc[:n]
17871787

@@ -1794,6 +1794,24 @@ def tail(self, n=5):
17941794
return self
17951795
return self.iloc[-n:]
17961796

1797+
def left(self, n=5):
1798+
"""
1799+
Return first n columns
1800+
"""
1801+
l = self.shape[1]
1802+
if l == 0 or n == 0:
1803+
return self
1804+
return self.iloc[:, :n]
1805+
1806+
def right(self, n=5):
1807+
"""
1808+
Return last n columns
1809+
"""
1810+
l = self.shape[1]
1811+
if l == 0 or n == 0:
1812+
return self
1813+
return self.iloc[:, -n:]
1814+
17971815
#----------------------------------------------------------------------
17981816
# Attribute access
17991817

0 commit comments

Comments
 (0)