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

Function from_dask_array

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

5120
5121
5122def from_dask_array(x, columns=None, index=None, meta=None) -> DataFrame:
5123 """Create a Dask DataFrame from a Dask Array.
5124
5125 Converts a 2d array into a DataFrame and a 1d array into a Series.
5126
5127 Parameters
5128 ----------
5129 x : da.Array
5130 columns : list or string
5131 list of column names if DataFrame, single string if Series
5132 index : dask.dataframe.Index, optional
5133 An optional *dask* Index to use for the output Series or DataFrame.
5134
5135 The default output index depends on whether `x` has any unknown
5136 chunks. If there are any unknown chunks, the output has ``None``
5137 for all the divisions (one per chunk). If all the chunks are known,
5138 a default index with known divisions is created.
5139
5140 Specifying `index` can be useful if you're conforming a Dask Array
5141 to an existing dask Series or DataFrame, and you would like the
5142 indices to match.
5143 meta : object, optional
5144 An optional `meta` parameter can be passed for dask
5145 to specify the concrete dataframe type to be returned.
5146 By default, pandas DataFrame is used.
5147
5148 Examples
5149 --------
5150 >>> import dask.array as da
5151 >>> import dask.dataframe as dd
5152 >>> x = da.ones((4, 2), chunks=(2, 2))
5153 >>> df = dd.io.from_dask_array(x, columns=['a', 'b'])
5154 >>> df.compute()
5155 a b
5156 0 1.0 1.0
5157 1 1.0 1.0
5158 2 1.0 1.0
5159 3 1.0 1.0
5160
5161 See Also
5162 --------
5163 dask.bag.to_dataframe: from dask.bag
5164 dask.dataframe.DataFrame.values: Reverse conversion
5165 dask.dataframe.DataFrame.to_records: Reverse conversion
5166 """
5167 from dask.dataframe.io import from_dask_array
5168
5169 if columns is not None and isinstance(columns, list) and not len(columns):
5170 columns = None
5171 return from_dask_array(x, columns=columns, index=index, meta=meta)
5172
5173
5174@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