Fill in NaNs by interpolating according to different methods. Parameters ---------- dim : Hashable or None, optional Specifies the dimension along which to interpolate. method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial",
(
self,
dim: Hashable | None = None,
method: InterpOptions = "linear",
limit: int | None = None,
use_coordinate: bool | Hashable = True,
max_gap: (
int
| float
| str
| pd.Timedelta
| np.timedelta64
| datetime.timedelta
| None
) = None,
**kwargs: Any,
)
| 6514 | return out |
| 6515 | |
| 6516 | def interpolate_na( |
| 6517 | self, |
| 6518 | dim: Hashable | None = None, |
| 6519 | method: InterpOptions = "linear", |
| 6520 | limit: int | None = None, |
| 6521 | use_coordinate: bool | Hashable = True, |
| 6522 | max_gap: ( |
| 6523 | int |
| 6524 | | float |
| 6525 | | str |
| 6526 | | pd.Timedelta |
| 6527 | | np.timedelta64 |
| 6528 | | datetime.timedelta |
| 6529 | | None |
| 6530 | ) = None, |
| 6531 | **kwargs: Any, |
| 6532 | ) -> Self: |
| 6533 | """Fill in NaNs by interpolating according to different methods. |
| 6534 | |
| 6535 | Parameters |
| 6536 | ---------- |
| 6537 | dim : Hashable or None, optional |
| 6538 | Specifies the dimension along which to interpolate. |
| 6539 | method : {"linear", "nearest", "zero", "slinear", "quadratic", "cubic", "polynomial", \ |
| 6540 | "barycentric", "krogh", "pchip", "spline", "akima"}, default: "linear" |
| 6541 | String indicating which method to use for interpolation: |
| 6542 | |
| 6543 | - 'linear': linear interpolation. Additional keyword |
| 6544 | arguments are passed to :py:func:`numpy.interp` |
| 6545 | - 'nearest', 'zero', 'slinear', 'quadratic', 'cubic', 'polynomial': |
| 6546 | are passed to :py:func:`scipy.interpolate.interp1d`. If |
| 6547 | ``method='polynomial'``, the ``order`` keyword argument must also be |
| 6548 | provided. |
| 6549 | - 'barycentric', 'krogh', 'pchip', 'spline', 'akima': use their |
| 6550 | respective :py:class:`scipy.interpolate` classes. |
| 6551 | |
| 6552 | use_coordinate : bool or Hashable, default: True |
| 6553 | Specifies which index to use as the x values in the interpolation |
| 6554 | formulated as `y = f(x)`. If False, values are treated as if |
| 6555 | equally-spaced along ``dim``. If True, the IndexVariable `dim` is |
| 6556 | used. If ``use_coordinate`` is a string, it specifies the name of a |
| 6557 | coordinate variable to use as the index. |
| 6558 | limit : int, default: None |
| 6559 | Maximum number of consecutive NaNs to fill. Must be greater than 0 |
| 6560 | or None for no limit. This filling is done regardless of the size of |
| 6561 | the gap in the data. To only interpolate over gaps less than a given length, |
| 6562 | see ``max_gap``. |
| 6563 | max_gap : int, float, str, pandas.Timedelta, numpy.timedelta64, datetime.timedelta \ |
| 6564 | or None, default: None |
| 6565 | Maximum size of gap, a continuous sequence of NaNs, that will be filled. |
| 6566 | Use None for no limit. When interpolating along a datetime64 dimension |
| 6567 | and ``use_coordinate=True``, ``max_gap`` can be one of the following: |
| 6568 | |
| 6569 | - a string that is valid input for pandas.to_timedelta |
| 6570 | - a :py:class:`numpy.timedelta64` object |
| 6571 | - a :py:class:`pandas.Timedelta` object |
| 6572 | - a :py:class:`datetime.timedelta` object |
| 6573 |