Skip to content

DOC: Adding example to head and tail method (#16416) #18749

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

Merged
merged 1 commit into from
Dec 15, 2017

Conversation

Cheukting
Copy link
Contributor

@Cheukting Cheukting commented Dec 12, 2017

closes #18691

@pep8speaks
Copy link

pep8speaks commented Dec 12, 2017

Hello @Cheukting! Thanks for updating the PR.

Cheers ! There are no PEP8 issues in this Pull Request. 🍻

Comment last updated on December 15, 2017 at 13:34 Hours UTC

@codecov
Copy link

codecov bot commented Dec 12, 2017

Codecov Report

Merging #18749 into master will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18749      +/-   ##
==========================================
- Coverage   91.63%   91.62%   -0.02%     
==========================================
  Files         154      154              
  Lines       51422    51422              
==========================================
- Hits        47121    47114       -7     
- Misses       4301     4308       +7
Flag Coverage Δ
#multiple 89.48% <ø> (ø) ⬆️
#single 40.82% <ø> (-0.12%) ⬇️
Impacted Files Coverage Δ
pandas/core/generic.py 95.9% <ø> (ø) ⬆️
pandas/io/gbq.py 25% <0%> (-58.34%) ⬇️
pandas/core/frame.py 97.68% <0%> (-0.11%) ⬇️
pandas/util/testing.py 82.91% <0%> (+0.19%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fe900cb...e730630. Read the comment docs.

@jreback
Copy link
Contributor

jreback commented Dec 13, 2017

can you also add a See Also section to both .head & .tail, this could close #18691

@jreback jreback added the Output-Formatting __repr__ of pandas objects, to_string label Dec 13, 2017
@jreback jreback added this to the 0.22.0 milestone Dec 13, 2017
@jreback jreback added the Docs label Dec 13, 2017
@jreback
Copy link
Contributor

jreback commented Dec 13, 2017

looks like this duplicates #18746 and was a little before yours. Happy to have you contribute on any other issues though!

@jreback jreback closed this Dec 13, 2017
@jreback jreback modified the milestones: 0.22.0, No action Dec 13, 2017
@datapythonista
Copy link
Member

@jreback, I think this PR is better than #18746. Sorry for the duplicate, they were both implemented in the same sprint, and people was supposed to notify on a gitter channel which methods they were working on, but we failed to do that successfully.

This PR documents both head and tail, and I think the example is a bit clearer. I'd probably use a sorted dataframe for better clarity, and I agree with the "See also" section. Are you ok reopening this PR, and closing the other as duplicate?

@Cheukting, can you add the See also section Jeff mentioned, and sort the dataframe so it's faster for people to see that the first or last rows are the ones returned?

For the See also, in the head you should mention the tail, and viceversa. You have an example of See also section here: https://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html

@jreback
Copy link
Contributor

jreback commented Dec 13, 2017

yeah happy to have either
will reopen and whomever wants to finish we can take

@Cheukting
Copy link
Contributor Author

@jreback @datapythonista it is all done, let me know if there more changes needed :-)

5 parrot
6 shark

Viewing the last 5 lines (the default)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last -> first

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes made

3 lion
4 monkey

Viewing the last n lines (three in this case)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same (actually needs editing as well)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By editing you mean?

@jreback jreback removed this from the No action milestone Dec 15, 2017
5 parrot
6 shark

Viewing the first 5 lines (the default)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you remove '(the default)' and from each of these (e.g. things in '()')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changes has been done :-)

@jreback jreback added this to the 0.22.0 milestone Dec 15, 2017
@datapythonista
Copy link
Member

Can I also suggest of having animals starting with A and Z in the list. So it's even more obvious (and faster to see) that the returned rows are the first and the last?

For example:

  • Alligator
  • Buffalo
  • ...
  • Whale
  • Zebra

I think we can save couple of seconds on understanding the example of each new pandas user that visit these pages. Which given the number of users of pandas, can be a lot of time. :)

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small comment

8 zebra

Viewing the first 5 lines
>>> df.head()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you keep a blank line between the explanation and the code line beginning with >>> ? (and the same for the other occurences)

This might be needed to satisfy sphinx (not fully sure), but I also think it improves readability

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changes has been done :-)


Examples
--------
>>> df = pd.DataFrame({'animal':['falcon', 'parrot', 'lion',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last typo, this dataframe should also include alligator, bee... it's inconsistent with the results now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed 👍

@jreback jreback merged commit c28b624 into pandas-dev:master Dec 15, 2017
@jreback
Copy link
Contributor

jreback commented Dec 15, 2017

thanks @Cheukting

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Docs Output-Formatting __repr__ of pandas objects, to_string
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an ends function that shows both head and tail of the df DOC: add examples to docstrings
5 participants