Skip to content

Commit

Permalink
xarray.dataset.head
Browse files Browse the repository at this point in the history
  • Loading branch information
harshitha1201 committed Jun 20, 2023
1 parent ee8ba41 commit 82e1161
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions xarray/core/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2740,6 +2740,43 @@ def head(
The keyword arguments form of ``indexers``.
One of indexers or indexers_kwargs must be provided.
Example
-------
# Sample Dataset
>>> dataset = xr.Dataset(
... {
... "temperature": [25.1, 28.3, 30.5, 27.2, 26.8],
... "humidity": [60.2, 55.6, 50.3, 58.8, 61.7],
... },
... coords={"time": [1, 2, 3, 4, 5]},
... )
# Originial Dataset
>>> dataset
<xarray.Dataset>
Dimensions: (temperature: 5, humidity: 5, time: 5)
Coordinates:
* temperature (temperature) float64 25.1 28.3 30.5 27.2 26.8
* humidity (humidity) float64 60.2 55.6 50.3 58.8 61.7
* time (time) int64 1 2 3 4 5
Data variables:
*empty*
# Use head() function to retrieve the first three elements
>>> head_dataset = dataset.head(2)
# Print the head dataset
>>> head_dataset
<xarray.Dataset>
Dimensions: (temperature: 2, humidity: 2, time: 2)
Coordinates:
* temperature (temperature) float64 25.1 28.3
* humidity (humidity) float64 60.2 55.6
* time (time) int64 1 2
Data variables:
*empty*
See Also
--------
Dataset.tail
Expand Down

0 comments on commit 82e1161

Please sign in to comment.