Skip to content

Formatting data array as strings? #5985

Open
@ahuang11

Description

#5865 (reply in thread)

I wonder if it's possible to implement a built-in function like:
da.str.format("%.2f") or xr.string_format(da, "%.2f)

To wrap:

import xarray as xr

da = xr.DataArray([5., 6., 7.])
das = xr.DataArray("%.2f")
das.str % da

<xarray.DataArray (dim_0: 3)>
array(['5.00', '6.00', '7.00'], dtype='<U4')
Dimensions without coordinates: dim_0

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions