@@ -999,24 +999,79 @@ def interpolate(
999
999
** kwargs ,
1000
1000
) -> Self :
1001
1001
"""
1002
- See DataFrame.interpolate.__doc__ .
1002
+ Fill NaN values using an interpolation method .
1003
1003
1004
+ Parameters
1005
+ ----------
1006
+ method : str, default 'linear'
1007
+ Interpolation technique to use. One of:
1008
+ * 'linear': Ignore the index and treat the values as equally spaced. This is the only method supported on MultiIndexes.
1009
+ * 'time': Works on daily and higher resolution data to interpolate given length of interval.
1010
+ * 'index', 'values': use the actual numerical values of the index.
1011
+ * 'pad': Fill in NaNs using existing values.
1012
+ * 'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'barycentric', 'polynomial':
1013
+ Passed to scipy.interpolate.interp1d, whereas 'spline' is passed to
1014
+ scipy.interpolate.UnivariateSpline. These methods use the numerical values of the index.
1015
+ Both 'polynomial' and 'spline' require that you also specify an order (int),
1016
+ e.g. arr.interpolate(method='polynomial', order=5).
1017
+ * 'krogh', 'piecewise_polynomial', 'spline', 'pchip', 'akima', 'cubicspline':
1018
+ Wrappers around the SciPy interpolation methods of similar names. See Notes.
1019
+ * 'from_derivatives': Refers to scipy.interpolate.BPoly.from_derivatives.
1020
+ axis : int
1021
+ Axis to interpolate along. For 1D NumpyExtensionArray, use 0.
1022
+ index : Index
1023
+ Index to use for interpolation.
1024
+ limit : int or None
1025
+ Maximum number of consecutive NaNs to fill. Must be greater than 0.
1026
+ limit_direction : {'forward', 'backward', 'both'}
1027
+ Consecutive NaNs will be filled in this direction.
1028
+ * If 'method' is 'pad' or 'ffill', 'limit_direction' must be 'forward'.
1029
+ * If 'method' is 'backfill' or 'bfill', 'limit_direction' must be 'backward'.
1030
+ Raises ValueError if limit_direction is 'forward' or 'both' and method is 'backfill' or 'bfill'.
1031
+ Raises ValueError if limit_direction is 'backward' or 'both' and method is 'pad' or 'ffill'.
1032
+ limit_area : {'inside', 'outside'} or None
1033
+ If limit is specified, consecutive NaNs will be filled with this restriction.
1034
+ * None: No fill restriction.
1035
+ * 'inside': Only fill NaNs surrounded by valid values (interpolate).
1036
+ * 'outside': Only fill NaNs outside valid values (extrapolate).
1037
+ copy : bool
1038
+ If True, a copy of the object is returned with interpolated values.
1039
+ **kwargs : optional
1040
+ Keyword arguments to pass on to the interpolating function.
1041
+
1042
+ Returns
1043
+ -------
1044
+ NumpyExtensionArray
1045
+ A new NumpyExtensionArray with interpolated values.
1046
+
1047
+ See Also
1048
+ --------
1049
+ Series.interpolate : Interpolate values in a Series.
1050
+ DataFrame.interpolate : Interpolate values in a DataFrame.
1051
+
1052
+ Notes
1053
+ -----
1054
+ - All parameters must be specified as keyword arguments.
1055
+ - The 'krogh', 'piecewise_polynomial', 'spline', 'pchip' and 'akima'
1056
+ methods are wrappers around the respective SciPy implementations of
1057
+ similar names. These use the actual numerical values of the index.
1058
+ - For 1D NumpyExtensionArray, use 0 for the `axis` parameter.
1059
+
1004
1060
Examples
1005
1061
--------
1006
- >>> arr = pd.arrays.NumpyExtensionArray(np.array([0, 1, np.nan, 3 ]))
1062
+ >>> arr = pd.arrays.NumpyExtensionArray(np.array([0, np.nan, 2, np.nan, 4 ]))
1007
1063
>>> arr.interpolate(
1008
- ... method="linear",
1009
- ... limit=3,
1010
- ... limit_direction="forward",
1011
- ... index=pd.Index([1, 2, 3, 4]),
1012
- ... fill_value=1,
1013
- ... copy=False,
1064
+ ... method='linear',
1014
1065
... axis=0,
1015
- ... limit_area="inside",
1066
+ ... index=pd.Index(range(len(arr))),
1067
+ ... limit=None,
1068
+ ... limit_direction='forward',
1069
+ ... limit_area=None,
1070
+ ... copy=True
1016
1071
... )
1017
1072
<NumpyExtensionArray>
1018
- [0.0, 1.0, 2.0, 3.0]
1019
- Length: 4 , dtype: float64
1073
+ [0.0, 1.0, 2.0, 3.0, 4.0 ]
1074
+ Length: 5 , dtype: float64
1020
1075
"""
1021
1076
# NB: we return type(self) even if copy=False
1022
1077
raise NotImplementedError (
0 commit comments