-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
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
[Issue: #16416] Adding examples for some DataFrame methods #16437
Conversation
pandas/core/frame.py
Outdated
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. |
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.
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.
pandas/core/frame.py
Outdated
|
||
Replace all NaN elements in column 'A', 'B', 'C', and 'D', with 0, 1, 2, and 3 respectively. | ||
|
||
>>> values = { |
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.
Maybe do this all on one line? Just since terminal space can be a bit precious.
This looks great! Could you also add an example with a |
pandas/core/frame.py
Outdated
|
||
Only replace the first NaN element. | ||
|
||
>>> values = { |
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.
Oh and the values
variable is still around, so you don't have to redefine it here.
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 |
Codecov Report
@@ Coverage Diff @@
## master #16437 +/- ##
=======================================
Coverage 90.42% 90.42%
=======================================
Files 161 161
Lines 51023 51023
=======================================
Hits 46138 46138
Misses 4885 4885
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #16437 +/- ##
=======================================
Coverage 90.4% 90.4%
=======================================
Files 161 161
Lines 51033 51033
=======================================
Hits 46136 46136
Misses 4897 4897
Continue to review full report at Codecov.
|
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.
Really nice examples!!
added a few comments
pandas/core/frame.py
Outdated
@@ -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 |
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.
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.
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.
One possible solution is putting the examples in the _shared_docs['fillna']
pandas/core/frame.py
Outdated
2, and 3 respectively. | ||
|
||
>>> values = {'A': 0, 'B': 1, 'C': 2, 'D': 3} | ||
... df.fillna(value=values) |
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.
>>>
instead of ...
pandas/core/generic.py
Outdated
... [3, 4, np.nan, 1], | ||
... [np.nan, np.nan, np.nan, 5], | ||
... [np.nan, 3, np.nan, 4] | ||
... ], |
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.
I would just use a Frame with numbers (without the NaNs), the NaNs are not really an added value to the example
Thanks @jorisvandenbossche! Fixed up some of those examples, what do you think now? |
moving fillna to generic and fixing a typo
Thanks @VincentLa |
* 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
Adding examples for
fillna
,drop
, andsort_values
.git diff upstream/master --name-only -- '*.py' | flake8 --diff