Search code examples
pythondatasetarviz

Getting number out of dataset python


I have a dataset, let's call it A, and when I print it looks like this:

<xarray.Dataset>
Dimensions:  (x_dim_0: 2)
Coordinates:
  * x_dim_0  (x_dim_0) int64 0 1
Data variables:
    x        (x_dim_0) float64 158.0 725.2

but now I want to extract the 158.0 and 725.2 and save them in a separate array, but I can't figure out how to get the values. I have tried A.x, A.get(), etc. Thanks!


Solution

  • You have to first select which variable do you want, x in this case, in order to get a DataArray from the Dataset and once you have a DataArray use .values.

    In this case it would be:

    A["x"].values
    # or what is the same A.x.values