MCPcopy
hub / github.com/pydata/xarray / dropna

Method dropna

xarray/core/dataset.py:6302–6434  ·  view source on GitHub ↗

Returns a new dataset with dropped labels for missing values along the provided dimension. Parameters ---------- dim : hashable Dimension along which to drop missing values. Dropping along multiple dimensions simultaneously is not yet supporte

(
        self,
        dim: Hashable,
        *,
        how: Literal["any", "all"] = "any",
        thresh: int | None = None,
        subset: Iterable[Hashable] | None = None,
    )

Source from the content-addressed store, hash-verified

6300 return ds
6301
6302 def dropna(
6303 self,
6304 dim: Hashable,
6305 *,
6306 how: Literal["any", "all"] = "any",
6307 thresh: int | None = None,
6308 subset: Iterable[Hashable] | None = None,
6309 ) -> Self:
6310 """Returns a new dataset with dropped labels for missing values along
6311 the provided dimension.
6312
6313 Parameters
6314 ----------
6315 dim : hashable
6316 Dimension along which to drop missing values. Dropping along
6317 multiple dimensions simultaneously is not yet supported.
6318 how : {"any", "all"}, default: "any"
6319 - any : if any NA values are present, drop that label
6320 - all : if all values are NA, drop that label
6321
6322 thresh : int or None, optional
6323 If supplied, require this many non-NA values (summed over all the subset variables).
6324 subset : iterable of hashable or None, optional
6325 Which variables to check for missing values. By default, all
6326 variables in the dataset are checked.
6327
6328 Examples
6329 --------
6330 >>> dataset = xr.Dataset(
6331 ... {
6332 ... "temperature": (
6333 ... ["time", "location"],
6334 ... [[23.4, 24.1], [np.nan, 22.1], [21.8, 24.2], [20.5, 25.3]],
6335 ... )
6336 ... },
6337 ... coords={"time": [1, 2, 3, 4], "location": ["A", "B"]},
6338 ... )
6339 >>> dataset
6340 <xarray.Dataset> Size: 104B
6341 Dimensions: (time: 4, location: 2)
6342 Coordinates:
6343 * time (time) int64 32B 1 2 3 4
6344 * location (location) <U1 8B 'A' 'B'
6345 Data variables:
6346 temperature (time, location) float64 64B 23.4 24.1 nan ... 24.2 20.5 25.3
6347
6348 Drop NaN values from the dataset
6349
6350 >>> dataset.dropna(dim="time")
6351 <xarray.Dataset> Size: 80B
6352 Dimensions: (time: 3, location: 2)
6353 Coordinates:
6354 * time (time) int64 24B 1 3 4
6355 * location (location) <U1 8B 'A' 'B'
6356 Data variables:
6357 temperature (time, location) float64 48B 23.4 24.1 21.8 24.2 20.5 25.3
6358
6359 Drop labels with any NaN values

Callers 14

test_dropnaMethod · 0.95
test_dropnaMethod · 0.95
test_dropnaMethod · 0.95
_get_index_and_itemsMethod · 0.45
compute_chunksMethod · 0.45
compute_chunksMethod · 0.45
test_groupby_drops_nansFunction · 0.45
test_dropnaMethod · 0.45

Calls 4

iselMethod · 0.95
to_numpyFunction · 0.90
countMethod · 0.45
prodMethod · 0.45

Tested by 10

test_dropnaMethod · 0.76
test_dropnaMethod · 0.76
test_dropnaMethod · 0.76
test_groupby_drops_nansFunction · 0.36
test_dropnaMethod · 0.36
test_series_dropnaFunction · 0.36
test_dropnaMethod · 0.36