Misdan Wijaya
Misdan Wijaya

Reputation: 49

Get value from xarray format in python

I try to get data from netCDF format with xarray

I have code like this,

import numpy as np
import pandas as pd
import xarray as xr
import sys, json
import base64

ds = xr.open_dataset('/home/misdan/Documents/Data/Angin/wind_1992.nc')
da = ds['u10'].sel(time='1992-02',latitude=6.0, longitude=95.20,method='nearest').data

print('--------------------------')
print('hasilnya adalah : ')
print(da)

The result is like this

hasilnya adalah : 
[-2.2909293]

how i can get the value from the result without [], like this

hasilnya adalah : 
-2.2909293

the data is like this

<xarray.DataArray 'u10' (time: 1)>
array([-2.290929], dtype=float32)
Coordinates:
    longitude  float32 95.25
    latitude   float32 6.0
  * time       (time) datetime64[ns] 1992-02-01
Attributes:
    units:      m s**-1
    long_name:  10 metre U wind component

Upvotes: 0

Views: 1670

Answers (1)

galfisher
galfisher

Reputation: 1122

print(da[0]) will print the first item in the da list, which is what you are looking for.

Upvotes: 2

Related Questions