fips.Operator.from_frame#

classmethod Operator.from_frame(frame, row_block=None, col_block=None, name=None)[source]#

Build an operator from a DataFrame, reading its labels.

Parameters:
  • frame (DataFrame) – The matrix. An axis with a block level has those blocks (see Space.from_index()), and the rows (or columns) of each block are put together, in the order the blocks first appear; an axis without one is one block, named by row_block or col_block. A frame with a pandas-sparse column is kept sparse; the entries a sparse column does not store are zeros.

  • row_block (str | None) – The name of the one block of an axis without a block level.

  • col_block (str | None) – The name of the one block of an axis without a block level.

  • name (str | None) – The operator’s name.

Returns:

The matrix on the spaces of the frame’s labels.

Return type:

Self

Raises:

ValueError – If an axis with a block level is given its block name too, or one without is not; its labels cannot make a Space; a sparse column has a fill value other than 0 or NaN; or an entry is NaN.

Examples

>>> import pandas as pd
>>> from fips import Operator
>>> frame = pd.DataFrame(
...     [[1.0, 0.5], [0.0, 2.0]],
...     index=pd.Index(["o1", "o2"], name="obs_id"),
...     columns=pd.Index(["a", "b"], name="cell"),
... )
>>> H = Operator.from_frame(frame, row_block="co2", col_block="flux")
>>> H.rows
Space(co2: 2 x ['obs_id'])
>>> H.to_frame().index.names
FrozenList(['block', 'obs_id'])