larray.from_frame

larray.from_frame(df, sort_rows=False, sort_columns=False, parse_header=False, unfold_last_axis_name=False, fill_value=nan, meta=None, cartesian_prod=True, copy=True, **kwargs) Array[source]

Convert Pandas DataFrame into Array.

Parameters:
dfpandas.DataFrame

Input dataframe. By default, name and labels of the last axis are defined by the name and labels of the columns Index of the dataframe unless argument unfold_last_axis_name is set to True.

sort_rowsbool, optional

Whether to sort the rows alphabetically (sorting is more efficient than not sorting). Must be False if cartesian_prod is set to True. Defaults to False.

sort_columnsbool, optional

Whether to sort the columns alphabetically (sorting is more efficient than not sorting). Must be False if cartesian_prod is set to True. Defaults to False.

parse_headerbool, optional

Whether to parse columns labels. Pandas treats column labels as strings. If True, column labels are converted into int, float or boolean when possible. Defaults to False.

unfold_last_axis_namebool, optional

Whether to extract the names of the last two axes by splitting the name of the last index column of the dataframe using \. Defaults to False.

fill_valuescalar, optional

Value used to fill cells corresponding to label combinations which are not present in the input DataFrame. Defaults to NaN.

metalist of pairs or dict or Metadata, optional

Metadata (title, description, author, creation_date, …) associated with the array. Keys must be strings. Values must be of type string, int, float, date, time or datetime.

cartesian_prodbool, optional

Whether to expand the dataframe to a cartesian product dataframe as needed by Array. This is an expensive operation but is absolutely required if you cannot guarantee your dataframe is already well-formed. If False, arguments sort_rows and sort_columns must also be False. Defaults to True.

copybool, optional

Whether to copy the data from the DataFrame. Defaults to True. copy=False does not guarantee that no copy will be made, only that a copy is only done when necessary. If the resulting array shares the same data buffer than the original series, it will be read-only.

Returns:
Array

See also

Array.to_frame

Examples

>>> from larray import ndtest
>>> df = ndtest((2, 2, 2)).to_frame()
>>> df
c      c0  c1
a  b
a0 b0   0   1
   b1   2   3
a1 b0   4   5
   b1   6   7
>>> from_frame(df)
 a  b\c  c0  c1
a0   b0   0   1
a0   b1   2   3
a1   b0   4   5
a1   b1   6   7