Fill NA/NaN values by propagating the last valid observation to next valid. Parameters ---------- axis : {0 or 'index'} for Series, {0 or 'index', 1 or 'columns'} for DataFrame Axis along which to fill missing values. For `Series` this parame
(
self,
*,
axis: None | Axis = None,
inplace: bool = False,
limit: None | int = None,
limit_area: Literal["inside", "outside"] | None = None,
)
| 7159 | |
| 7160 | @final |
| 7161 | def ffill( |
| 7162 | self, |
| 7163 | *, |
| 7164 | axis: None | Axis = None, |
| 7165 | inplace: bool = False, |
| 7166 | limit: None | int = None, |
| 7167 | limit_area: Literal["inside", "outside"] | None = None, |
| 7168 | ) -> Self: |
| 7169 | """ |
| 7170 | Fill NA/NaN values by propagating the last valid observation to next valid. |
| 7171 | |
| 7172 | Parameters |
| 7173 | ---------- |
| 7174 | axis : {0 or 'index'} for Series, {0 or 'index', 1 or 'columns'} for DataFrame |
| 7175 | Axis along which to fill missing values. For `Series` |
| 7176 | this parameter is unused and defaults to 0. |
| 7177 | inplace : bool, default False |
| 7178 | If True, fill in-place. Note: this will modify any |
| 7179 | other views on this object (e.g., a no-copy slice for a column in a |
| 7180 | DataFrame). |
| 7181 | limit : int, default None |
| 7182 | If method is specified, this is the maximum number of consecutive |
| 7183 | NaN values to forward/backward fill. In other words, if there is |
| 7184 | a gap with more than this number of consecutive NaNs, it will only |
| 7185 | be partially filled. If method is not specified, this is the |
| 7186 | maximum number of entries along the entire axis where NaNs will be |
| 7187 | filled. Must be greater than 0 if not None. |
| 7188 | limit_area : {`None`, 'inside', 'outside'}, default None |
| 7189 | If limit is specified, consecutive NaNs will be filled with this |
| 7190 | restriction. |
| 7191 | |
| 7192 | * ``None``: No fill restriction. |
| 7193 | * 'inside': Only fill NaNs surrounded by valid values |
| 7194 | (interpolate). |
| 7195 | * 'outside': Only fill NaNs outside valid values (extrapolate). |
| 7196 | |
| 7197 | .. versionadded:: 2.2.0 |
| 7198 | |
| 7199 | Returns |
| 7200 | ------- |
| 7201 | Series/DataFrame |
| 7202 | Object with missing values filled. |
| 7203 | |
| 7204 | See Also |
| 7205 | -------- |
| 7206 | DataFrame.bfill : Fill NA/NaN values by using the next valid observation |
| 7207 | to fill the gap. |
| 7208 | |
| 7209 | Examples |
| 7210 | -------- |
| 7211 | >>> df = pd.DataFrame( |
| 7212 | ... [ |
| 7213 | ... [np.nan, 2, np.nan, 0], |
| 7214 | ... [3, 4, np.nan, 1], |
| 7215 | ... [np.nan, np.nan, np.nan, np.nan], |
| 7216 | ... [np.nan, 3, np.nan, 4], |
| 7217 | ... ], |
| 7218 | ... columns=list("ABCD"), |