Skip to content

DOC: Added example to NDFrame.where #13798

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
Aug 15, 2016

Conversation

jalexvig
Copy link
Contributor

No description provided.

________

>>> df = pd.DataFrame(np.arange(10).reshape(-1, 2), columns=['A', 'B'])
>>> df.where(df % 3, -df)
Copy link
Member

@sinhrks sinhrks Jul 26, 2016

Choose a reason for hiding this comment

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

as cond should be a boolean DataFrame, df % 3 != 0 is better as an example. Also, I prefer arange(1, 11) because -0 = 0 (or whatever example that user can clearly understand).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted and updated!

________

>>> df = pd.DataFrame(np.arange(10).reshape(-1, 2), columns=['A', 'B'])
>>> df.where(df % 3 == 0, -df)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed to boolean DataFrame and flipped bools so as to not induce confusion with 0 -> -0 -> 0.

@jreback
Copy link
Contributor

jreback commented Jul 26, 2016

I think adding how this can emulate np.where would also be useful (add in a Note section for that)

@jreback
Copy link
Contributor

jreback commented Jul 26, 2016

from your expl on SO

@codecov-io
Copy link

codecov-io commented Jul 27, 2016

Current coverage is 85.28% (diff: 100%)

Merging #13798 into master will increase coverage by <.01%

@@             master     #13798   diff @@
==========================================
  Files           139        139          
  Lines         50214      50214          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits          42822      42823     +1   
+ Misses         7392       7391     -1   
  Partials          0          0          

Powered by Codecov. Last update a0d05db...6ae0e79

@sinhrks sinhrks added this to the 0.19.0 milestone Jul 27, 2016
to `np.where(m, df1, df2`.

Examples
________
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 use dashes (-) instead of underscores (_)?

@jalexvig
Copy link
Contributor Author

  1. Added DataFrame.where/numpy.where example
  2. Updated note according to @jorisvandenbossche and @jreback comments

Thanks for feedback!

Notes
-----
The signature for :func:`DataFrame.where` differs from
:func:`numpy.where`. Roughly ``df1.where(m, df2)`` is equivalent to
Copy link
Contributor

Choose a reason for hiding this comment

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

you don't need the double-backticks here as this is not markdown.

Copy link
Member

Choose a reason for hiding this comment

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

jeff, it's the other way around :-) (it's markdown that does not need double backticks)

Copy link
Contributor

Choose a reason for hiding this comment

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

my bad, @jorisvandenbossche is right!

@jreback
Copy link
Contributor

jreback commented Aug 9, 2016

can you update

@jalexvig
Copy link
Contributor Author

Yep, will do.

On Tue, Aug 9, 2016 at 7:23 PM Jeff Reback [email protected] wrote:

can you update


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#13798 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AMGNkRIvNC29BQrB3AwVQdWQd7xWOpDyks5qeQwDgaJpZM4JUwF8
.

@jalexvig
Copy link
Contributor Author

I noticed that most examples on the method's page use the >>> syntax. Is it ok to use the .. ipython:: python rst directive to generate them?

@jreback
Copy link
Contributor

jreback commented Aug 13, 2016

@jalexvig no, use the doc-string syntax. These are viewable from the command line, not generated docs (they are generated too, but that's not the primary use)

@jorisvandenbossche jorisvandenbossche merged commit 5f49638 into pandas-dev:master Aug 15, 2016
@jorisvandenbossche
Copy link
Member

@jalexvig Thanks a lot!

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.

5 participants