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

Function from_dask_array

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

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