-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
Add example to Dataframe.head()
method's docstring.
#18746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
8581f97
f61d735
439f6be
94f2702
0ac5fab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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', np.nan, '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 NaN 8 4 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you adding a nan value? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NaN is used for marking missing values in string (object) dtype columns too, so this is OK. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. just copied from an example above, but I agree. It made sense in the |
||
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 NaN 8 4 | ||
4 D 7 2 | ||
|
||
Viewing the first n lines (three in this case) | ||
>>> df.head(n=3) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You don't need to specify
|
||
col1 col2 col3 | ||
0 A 2 0 | ||
1 A 1 1 | ||
2 B 9 9 | ||
|
||
""" | ||
|
||
return self.iloc[:n] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove extra space after you finish the string:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and being PEP8 compliant!