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

Method tail

xarray/core/dataset.py:3160–3249  ·  view source on GitHub ↗

Returns a new dataset with the last `n` values of each array for the specified dimension(s). Parameters ---------- indexers : dict or int, default: 5 A dict with keys matching dimensions and integer values `n` or a single integer `n` applied o

(
        self,
        indexers: Mapping[Any, int] | int | None = None,
        **indexers_kwargs: Any,
    )

Source from the content-addressed store, hash-verified

3158 return self.isel(indexers_slices)
3159
3160 def tail(
3161 self,
3162 indexers: Mapping[Any, int] | int | None = None,
3163 **indexers_kwargs: Any,
3164 ) -> Self:
3165 """Returns a new dataset with the last `n` values of each array
3166 for the specified dimension(s).
3167
3168 Parameters
3169 ----------
3170 indexers : dict or int, default: 5
3171 A dict with keys matching dimensions and integer values `n`
3172 or a single integer `n` applied over all dimensions.
3173 One of indexers or indexers_kwargs must be provided.
3174 **indexers_kwargs : {dim: n, ...}, optional
3175 The keyword arguments form of ``indexers``.
3176 One of indexers or indexers_kwargs must be provided.
3177
3178 Examples
3179 --------
3180 >>> activity_names = ["Walking", "Running", "Cycling", "Swimming", "Yoga"]
3181 >>> durations = [30, 45, 60, 45, 60] # in minutes
3182 >>> energies = [150, 300, 250, 400, 100] # in calories
3183 >>> dataset = xr.Dataset(
3184 ... {
3185 ... "duration": (["activity"], durations),
3186 ... "energy_expenditure": (["activity"], energies),
3187 ... },
3188 ... coords={"activity": activity_names},
3189 ... )
3190 >>> sorted_dataset = dataset.sortby("energy_expenditure", ascending=False)
3191 >>> sorted_dataset
3192 <xarray.Dataset> Size: 240B
3193 Dimensions: (activity: 5)
3194 Coordinates:
3195 * activity (activity) <U8 160B 'Swimming' 'Running' ... 'Yoga'
3196 Data variables:
3197 duration (activity) int64 40B 45 45 60 30 60
3198 energy_expenditure (activity) int64 40B 400 300 250 150 100
3199
3200 # Activities with the least energy expenditures using tail()
3201
3202 >>> sorted_dataset.tail(3)
3203 <xarray.Dataset> Size: 144B
3204 Dimensions: (activity: 3)
3205 Coordinates:
3206 * activity (activity) <U8 96B 'Cycling' 'Walking' 'Yoga'
3207 Data variables:
3208 duration (activity) int64 24B 60 30 60
3209 energy_expenditure (activity) int64 24B 250 150 100
3210
3211 >>> sorted_dataset.tail({"activity": 3})
3212 <xarray.Dataset> Size: 144B
3213 Dimensions: (activity: 3)
3214 Coordinates:
3215 * activity (activity) <U8 96B 'Cycling' 'Walking' 'Yoga'
3216 Data variables:
3217 duration (activity) int64 24B 60 30 60

Callers 2

test_tailMethod · 0.45
test_tailMethod · 0.45

Calls 5

iselMethod · 0.95
is_dict_likeFunction · 0.90
either_dict_or_kwargsFunction · 0.90
typeFunction · 0.85
itemsMethod · 0.80

Tested by 2

test_tailMethod · 0.36
test_tailMethod · 0.36