Movatterモバイル変換


[0]ホーム

URL:


Skip to main content
Ctrl+K

pandas.DataFrame.ffill#

DataFrame.ffill(*,axis=None,inplace=False,limit=None,limit_area=None,downcast=<no_default>)[source]#

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. ForSeriesthis parameter is unused and defaults to 0.

inplacebool, default False

If True, fill in-place. Note: this will modify anyother views on this object (e.g., a no-copy slice for a column in aDataFrame).

limitint, default None

If method is specified, this is the maximum number of consecutiveNaN values to forward/backward fill. In other words, if there isa gap with more than this number of consecutive NaNs, it will onlybe partially filled. If method is not specified, this is themaximum number of entries along the entire axis where NaNs will befilled. Must be greater than 0 if not None.

limit_area{None, ‘inside’, ‘outside’}, default None

If limit is specified, consecutive NaNs will be filled with thisrestriction.

  • None: No fill restriction.

  • ‘inside’: Only fill NaNs surrounded by valid values(interpolate).

  • ‘outside’: Only fill NaNs outside valid values (extrapolate).

Added in version 2.2.0.

downcastdict, default is None

A dict of item->dtype of what to downcast if possible,or the string ‘infer’ which will try to downcast to an appropriateequal type (e.g. float64 to int64 if possible).

Deprecated since version 2.2.0.

Returns:
Series/DataFrame or None

Object with missing values filled or None ifinplace=True.

Examples

>>>df=pd.DataFrame([[np.nan,2,np.nan,0],...[3,4,np.nan,1],...[np.nan,np.nan,np.nan,np.nan],...[np.nan,3,np.nan,4]],...columns=list("ABCD"))>>>df     A    B   C    D0  NaN  2.0 NaN  0.01  3.0  4.0 NaN  1.02  NaN  NaN NaN  NaN3  NaN  3.0 NaN  4.0
>>>df.ffill()     A    B   C    D0  NaN  2.0 NaN  0.01  3.0  4.0 NaN  1.02  3.0  4.0 NaN  1.03  3.0  3.0 NaN  4.0
>>>ser=pd.Series([1,np.nan,2,3])>>>ser.ffill()0   1.01   1.02   2.03   3.0dtype: float64

[8]ページ先頭

©2009-2025 Movatter.jp