Skip to content
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

[Issue: #16416] Adding examples for some DataFrame methods #16437

Merged
merged 7 commits into from
May 25, 2017
Merged

[Issue: #16416] Adding examples for some DataFrame methods #16437

merged 7 commits into from
May 25, 2017

Conversation

VincentLa
Copy link
Contributor

@VincentLa VincentLa commented May 22, 2017

Adding examples for fillna, drop, and sort_values.

1 3.0 4.0 0.0 1
2 0.0 0.0 0.0 5

Replace all NaN elements in column 'A', 'B', 'C', and 'D', with 0, 1, 2, and 3 respectively.
Copy link
Contributor

Choose a reason for hiding this comment

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

You might need to wrap this line (our style checker has a max line length of 80 characters). You can flake8 pandas/core/frame.py and it will print style errors.


Replace all NaN elements in column 'A', 'B', 'C', and 'D', with 0, 1, 2, and 3 respectively.

>>> values = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe do this all on one line? Just since terminal space can be a bit precious.

@TomAugspurger
Copy link
Contributor

This looks great! Could you also add an example with a method? Maybe just method='ffill'.

@TomAugspurger TomAugspurger added this to the 0.21.0 milestone May 22, 2017

Only replace the first NaN element.

>>> values = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh and the values variable is still around, so you don't have to redefine it here.

@VincentLa
Copy link
Contributor Author

VincentLa commented May 22, 2017

I'm also having some issues because when I build locally, the line, "Fill NA/NaN values using the specified method" seems to appear in the bottom of the documentation. I'm not sure why it doesn't stay at the top?

This line seems to be coming from here: https://github.com/pandas-dev/pandas/blob/master/pandas/core/generic.py#L3433

@VincentLa VincentLa changed the title [Issue: #16416] Adding examples to fillna [Issue: #16416] Adding examples for some DataFrame methods May 22, 2017
@VincentLa
Copy link
Contributor Author

@geoninja

@codecov
Copy link

codecov bot commented May 23, 2017

Codecov Report

Merging #16437 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #16437   +/-   ##
=======================================
  Coverage   90.42%   90.42%           
=======================================
  Files         161      161           
  Lines       51023    51023           
=======================================
  Hits        46138    46138           
  Misses       4885     4885
Flag Coverage Δ
#multiple 88.26% <ø> (ø) ⬆️
#single 40.17% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/frame.py 97.69% <ø> (ø) ⬆️
pandas/core/generic.py 92.13% <ø> (ø) ⬆️

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 49ec31b...cc734ba. Read the comment docs.

@codecov
Copy link

codecov bot commented May 23, 2017

Codecov Report

Merging #16437 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #16437   +/-   ##
=======================================
  Coverage    90.4%    90.4%           
=======================================
  Files         161      161           
  Lines       51033    51033           
=======================================
  Hits        46136    46136           
  Misses       4897     4897
Flag Coverage Δ
#multiple 88.24% <ø> (ø) ⬆️
#single 40.17% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/generic.py 92.13% <ø> (ø) ⬆️

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 97ad3fb...fe13093. Read the comment docs.

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.

Really nice examples!!

added a few comments

@@ -2915,6 +2915,59 @@ def rename(self, index=None, columns=None, **kwargs):
@Appender(_shared_docs['fillna'] % _shared_doc_kwargs)
def fillna(self, value=None, method=None, axis=None, inplace=False,
limit=None, downcast=None, **kwargs):
"""
Examples
Copy link
Member

Choose a reason for hiding this comment

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

Putting those examples here won't work, as now the rest of the docstring is appended to the examples, while the examples should come at the end.

Copy link
Member

Choose a reason for hiding this comment

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

One possible solution is putting the examples in the _shared_docs['fillna']

2, and 3 respectively.

>>> values = {'A': 0, 'B': 1, 'C': 2, 'D': 3}
... df.fillna(value=values)
Copy link
Member

Choose a reason for hiding this comment

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

>>> instead of ...

... [3, 4, np.nan, 1],
... [np.nan, np.nan, np.nan, 5],
... [np.nan, 3, np.nan, 4]
... ],
Copy link
Member

Choose a reason for hiding this comment

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

I would just use a Frame with numbers (without the NaNs), the NaNs are not really an added value to the example

@VincentLa
Copy link
Contributor Author

VincentLa commented May 24, 2017

Thanks @jorisvandenbossche! Fixed up some of those examples, what do you think now?

@TomAugspurger TomAugspurger merged commit e81f3cc into pandas-dev:master May 25, 2017
@TomAugspurger
Copy link
Contributor

Thanks @VincentLa

stangirala pushed a commit to stangirala/pandas that referenced this pull request Jun 11, 2017
* Adding examples to fillna

* putting better spacing

* removing unnecessary values variable

* Adding an example for method ffill

* adding examples for drop method

* Adding examples for sort_values

* Fixing linter error

moving fillna to generic and fixing a typo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants