Skip to content

Allow passing a default value (instead of ndarray) for data argument for DataArray #878

@joonro

Description

@joonro

Hi,

First of all, thanks a lot for the amazing module. It seems when I create a DataArray, I have to pass a numpy.ndarray with a correct size for the data argument. It works well when I already have some data, but sometimes I want to create an "empty" DataArray with known coordinates and fill up the data later. For these cases, it would be great if xarray allows passing just a value for the data argument, and fill up all the elements of the array with the value. For example, with pandas, I can do:

import pandas as pd
test = pd.DataFrame(data=.1, index=range(100), columns=['col1', 'col2'])

and the resulting DataFrame would be:

    col1  col2
0    0.1   0.1
1    0.1   0.1
2    0.1   0.1
..   ...   ...
97   0.1   0.1
98   0.1   0.1
99   0.1   0.1

[100 rows x 2 columns]

Thanks a lot!

Metadata

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