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 ablocklevel has those blocks (seeSpace.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 ablocklevel.col_block (
str|None) – The name of the one block of an axis without ablocklevel.
- Returns:
The matrix on the spaces of the frame’s labels.
- Return type:
- Raises:
ValueError – If an axis with a
blocklevel is given its block name too, or one without is not; its labels cannot make aSpace; 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'])