xarray.Dataset.set_coords (original) (raw)

Dataset.set_coords(names)[source]#

Given names of one or more variables, set them as coordinates

Parameters:

names (hashable or iterable of hashable) – Name(s) of variables in this dataset to convert into coordinates.

Examples

dataset = xr.Dataset( ... { ... "pressure": ("time", [1.013, 1.2, 3.5]), ... "time": pd.date_range("2023-01-01", periods=3), ... } ... ) dataset <xarray.Dataset> Size: 48B Dimensions: (time: 3) Coordinates:

dataset.set_coords("pressure") <xarray.Dataset> Size: 48B Dimensions: (time: 3) Coordinates: pressure (time) float64 24B 1.013 1.2 3.5

On calling set_coords , these data variables are converted to coordinates, as shown in the final dataset.

Returns:

Dataset