Block Structures#

Block#

Constructor#

Block(data[, name, index, dtype, copy])

Single data block with a named Series and consistent index.

Attributes and underlying data#

Block.name

The name of the underlying Series.

Block.data

The underlying data, which must be numeric and non-NaN.

Block.index

Return the index of the underlying data.

Conversion#

Block.copy([deep])

Create a copy of the structure.

Block.to_series([add_block_level])

Return the underlying Series data.

Block.to_numpy()

Get the underlying data as a NumPy array.

Block.to_xarray()

Convert the Block to an xarray DataArray.

Reindexing / selection / label manipulation#

Block.xs(key[, axis, level, drop_level])

Cross-select data based on index/column values.

Block.reindex(index[, columns, ...])

Return a new instance with data reindexed to the specified index and columns.

Block.round_index(decimals[, axis, inplace])

Round float indices on the specified axis to given decimals.

Serialization#

Block.from_file(path)

Load object from a pickle file.

Block.to_file(path)

Save object to a pickle file.

MatrixBlock#

Constructor#

MatrixBlock(data[, row_block, col_block, ...])

Single 2D data block with row and column block names.

Attributes and underlying data#

MatrixBlock.name

Name of the structure, used for error messages and block naming.

MatrixBlock.data

The underlying data, which must be numeric and non-NaN.

MatrixBlock.row_block

Name of the row block (e.g., 'state', 'obs').

MatrixBlock.col_block

Name of the column block (e.g., 'state', 'obs').

MatrixBlock.index

Return the index of the underlying data.

MatrixBlock.columns

Return the columns of the underlying DataFrame.

MatrixBlock.shape

Return the shape of the underlying data.

MatrixBlock.values

Return values as numpy array or sparse matrix.

Conversion#

MatrixBlock.copy([deep])

Create a copy of the structure.

MatrixBlock.to_frame([add_block_level])

Convert to DataFrame with optional block level.

MatrixBlock.to_numpy()

Get the underlying data as a NumPy array.

Reindexing / selection / label manipulation#

MatrixBlock.xs(key[, axis, level, drop_level])

Cross-select data based on index/column values.

MatrixBlock.reindex(index[, columns, ...])

Return a new instance with data reindexed to the specified index and columns.

MatrixBlock.round_index(decimals[, axis, ...])

Round float indices on the specified axis to given decimals.

Serialization#

MatrixBlock.from_file(path)

Load object from a pickle file.

MatrixBlock.to_file(path)

Save object to a pickle file.

Sparse support#

MatrixBlock.is_sparse

True if the internal DataFrame uses pandas sparse storage.

MatrixBlock.to_sparse([threshold])

Return a copy with sparse internal storage.

MatrixBlock.to_dense()

Return a copy with dense internal storage.