MCPcopy
hub / github.com/dask/dask / from_dask_array

Function from_dask_array

dask/dataframe/dask_expr/_collection.py:5087–5136  ·  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

5085
5086
5087def from_dask_array(x, columns=None, index=None, meta=None) -> DataFrame:
5088 """Create a Dask DataFrame from a Dask Array.
5089
5090 Converts a 2d array into a DataFrame and a 1d array into a Series.
5091
5092 Parameters
5093 ----------
5094 x : da.Array
5095 columns : list or string
5096 list of column names if DataFrame, single string if Series
5097 index : dask.dataframe.Index, optional
5098 An optional *dask* Index to use for the output Series or DataFrame.
5099
5100 The default output index depends on whether `x` has any unknown
5101 chunks. If there are any unknown chunks, the output has ``None``
5102 for all the divisions (one per chunk). If all the chunks are known,
5103 a default index with known divisions is created.
5104
5105 Specifying `index` can be useful if you're conforming a Dask Array
5106 to an existing dask Series or DataFrame, and you would like the
5107 indices to match.
5108 meta : object, optional
5109 An optional `meta` parameter can be passed for dask
5110 to specify the concrete dataframe type to be returned.
5111 By default, pandas DataFrame is used.
5112
5113 Examples
5114 --------
5115 >>> import dask.array as da
5116 >>> import dask.dataframe as dd
5117 >>> x = da.ones((4, 2), chunks=(2, 2))
5118 >>> df = dd.io.from_dask_array(x, columns=['a', 'b'])
5119 >>> df.compute()
5120 a b
5121 0 1.0 1.0
5122 1 1.0 1.0
5123 2 1.0 1.0
5124 3 1.0 1.0
5125
5126 See Also
5127 --------
5128 dask.bag.to_dataframe: from dask.bag
5129 dask.dataframe.DataFrame.values: Reverse conversion
5130 dask.dataframe.DataFrame.to_records: Reverse conversion
5131 """
5132 from dask.dataframe.io import from_dask_array
5133
5134 if columns is not None and isinstance(columns, list) and not len(columns):
5135 columns = None
5136 return from_dask_array(x, columns=columns, index=index, meta=meta)
5137
5138
5139@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

Used in the wild real call sites across dependent graphs

searching dependent graphs…