Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 38 additions & 2 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -2966,8 +2966,8 @@ def add_suffix(self, suffix):
Examples
--------
>>> df = pd.DataFrame({
... 'col1' : ['A', 'A', 'B', np.nan, 'D', 'C'],
... 'col2' : [2, 1, 9, 8, 7, 4],
... 'col1': ['A', 'A', 'B', np.nan, 'D', 'C'],
... 'col2': [2, 1, 9, 8, 7, 4],
... 'col3': [0, 1, 9, 4, 2, 3],
... })
>>> df
Expand Down Expand Up @@ -3563,6 +3563,42 @@ def head(self, n=5):
-------
obj_head : type of caller
The first n rows of the caller object.

Examples
--------
>>> df = pd.DataFrame({
... 'col1': ['A', 'A', 'B', 'B', 'D', 'C', 'E', 'E', 'F'],
... 'col2': [2, 1, 9, 8, 7, 4, 0, 2, 2],
... 'col3': [0, 1, 9, 4, 2, 3, 5, 7, 3],
... })
>>> df
col1 col2 col3
0 A 2 0
1 A 1 1
2 B 9 9
3 B 8 4
4 D 7 2
5 C 4 3
6 E 0 5
7 E 2 7
8 F 2 3

Viewing the first 5 lines (the default)
>>> df.head()
col1 col2 col3
0 A 2 0
1 A 1 1
2 B 9 9
3 B 8 4
4 D 7 2

Viewing the first n lines (three in this case)
>>> df.head(3)
col1 col2 col3
0 A 2 0
1 A 1 1
2 B 9 9

"""

return self.iloc[:n]
Expand Down