-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: update the pandas.core.resample.Resampler.backfill docstring #20083
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 4 commits
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 |
---|---|---|
|
@@ -519,21 +519,64 @@ def nearest(self, limit=None): | |
|
||
def backfill(self, limit=None): | ||
""" | ||
Backward fill the values | ||
Backward fill the values. | ||
|
||
In statistics, imputation is the process of replacing missing data with | ||
substituted values [1]_. When resampling data, missing values may | ||
appear (e.g., when the resampling frequency is higher than the original | ||
frequency). The backward fill will replace NA values with the next | ||
non-NA value in the sequence. | ||
|
||
Parameters | ||
---------- | ||
limit : integer, optional | ||
limit of how many values to fill | ||
Limit of how many values to fill. | ||
|
||
Returns | ||
------- | ||
an upsampled Series | ||
Series | ||
An upsampled Series with backward filled NA values. | ||
|
||
See Also | ||
-------- | ||
Series.fillna | ||
DataFrame.fillna | ||
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. can you add a Resampler.pad, nearest, and fillna refs @jorisvandenbossche how do we reference these exactly here? 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. It might be you can simply refer to them as 'pad', 'nearest', .. because they live on the same class. But need to check. 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. If I run |
||
Series.fillna : Fill NA/NaN values in the Series using the specified | ||
method, which can be 'backfill'. | ||
DataFrame.fillna : Fill NA/NaN values in the DataFrame using the | ||
specified method, which can be 'backfill'. | ||
|
||
References | ||
---------- | ||
.. [1] https://en.wikipedia.org/wiki/Imputation_(statistics) | ||
|
||
Examples | ||
-------- | ||
>>> s = pd.Series([1, 2, 3], | ||
... index=pd.date_range('20180101', periods=3, freq='h')) | ||
>>> s | ||
2018-01-01 00:00:00 1 | ||
2018-01-01 01:00:00 2 | ||
2018-01-01 02:00:00 3 | ||
Freq: H, dtype: int64 | ||
|
||
>>> s.resample('30min').backfill() | ||
2018-01-01 00:00:00 1 | ||
2018-01-01 00:30:00 2 | ||
2018-01-01 01:00:00 2 | ||
2018-01-01 01:30:00 3 | ||
2018-01-01 02:00:00 3 | ||
Freq: 30T, dtype: int64 | ||
|
||
>>> s.resample('15min').backfill(limit=2) | ||
2018-01-01 00:00:00 1.0 | ||
2018-01-01 00:15:00 NaN | ||
2018-01-01 00:30:00 2.0 | ||
2018-01-01 00:45:00 2.0 | ||
2018-01-01 01:00:00 2.0 | ||
2018-01-01 01:15:00 NaN | ||
2018-01-01 01:30:00 3.0 | ||
2018-01-01 01:45:00 3.0 | ||
2018-01-01 02:00:00 3.0 | ||
Freq: 15T, dtype: float64 | ||
""" | ||
return self._upsample('backfill', limit=limit) | ||
bfill = backfill | ||
|
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.
It might be interesting to add a more thorough explanation of what exactly is a backward fill for novice users who have never seem this term. Something along the lines of: 'get all the NA values and substitute with the value on the next row that has a non-NA value'
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.
if you can find a wikipedia reference would be great as well.