MCPcopy Create free account
hub / github.com/dask/dask / from_dask_array

Function from_dask_array

dask/dataframe/dask_expr/_collection.py:5044–5093  ·  view source on GitHub ↗

Create a Dask DataFrame from a Dask Array. Converts a 2d array into a DataFrame and a 1d array into a Series. Parameters ---------- x : da.Array columns : list or string list of column names if DataFrame, single string if Series index : dask.dataframe.Index, optiona

(x, columns=None, index=None, meta=None)

Source from the content-addressed store, hash-verified

5042
5043
5044def from_dask_array(x, columns=None, index=None, meta=None) -> DataFrame:
5045 """Create a Dask DataFrame from a Dask Array.
5046
5047 Converts a 2d array into a DataFrame and a 1d array into a Series.
5048
5049 Parameters
5050 ----------
5051 x : da.Array
5052 columns : list or string
5053 list of column names if DataFrame, single string if Series
5054 index : dask.dataframe.Index, optional
5055 An optional *dask* Index to use for the output Series or DataFrame.
5056
5057 The default output index depends on whether `x` has any unknown
5058 chunks. If there are any unknown chunks, the output has ``None``
5059 for all the divisions (one per chunk). If all the chunks are known,
5060 a default index with known divisions is created.
5061
5062 Specifying `index` can be useful if you're conforming a Dask Array
5063 to an existing dask Series or DataFrame, and you would like the
5064 indices to match.
5065 meta : object, optional
5066 An optional `meta` parameter can be passed for dask
5067 to specify the concrete dataframe type to be returned.
5068 By default, pandas DataFrame is used.
5069
5070 Examples
5071 --------
5072 >>> import dask.array as da
5073 >>> import dask.dataframe as dd
5074 >>> x = da.ones((4, 2), chunks=(2, 2))
5075 >>> df = dd.io.from_dask_array(x, columns=['a', 'b'])
5076 >>> df.compute()
5077 a b
5078 0 1.0 1.0
5079 1 1.0 1.0
5080 2 1.0 1.0
5081 3 1.0 1.0
5082
5083 See Also
5084 --------
5085 dask.bag.to_dataframe: from dask.bag
5086 dask.dataframe.DataFrame.values: Reverse conversion
5087 dask.dataframe.DataFrame.to_records: Reverse conversion
5088 """
5089 from dask.dataframe.io import from_dask_array
5090
5091 if columns is not None and isinstance(columns, list) and not len(columns):
5092 columns = None
5093 return from_dask_array(x, columns=columns, index=index, meta=meta)
5094
5095
5096@dataframe_creation_dispatch.register_inplace("pandas")

Callers 7

_loc_arrayMethod · 0.90
_wrap_expr_opFunction · 0.90
assignMethod · 0.90
from_arrayFunction · 0.90
test_from_dask_arrayFunction · 0.90

Calls

no outgoing calls

Tested by 3

test_from_dask_arrayFunction · 0.72