Skip to content

How to format numbers in xarray? #5865

Answered by andersy005
ahuang11 asked this question in Q&A
Discussion options

You must be logged in to vote

@ahuang11, would this work for you?

In [9]: import xarray as xr

In [10]: da = xr.DataArray([5., 6., 7.])

In [11]: xr.DataArray([f"{s:.2f}" for s in da.data])
Out[11]: 
<xarray.DataArray (dim_0: 3)>
array(['5.00', '6.00', '7.00'], dtype='<U4')
Dimensions without coordinates: dim_0

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@ahuang11
Comment options

@fmaussion
Comment options

@ahuang11
Comment options

Answer selected by ahuang11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants