_Assay.crosstab

_Assay.crosstab#

missionbio.mosaic.assay._Assay.crosstab

_Assay.crosstab(columns: Union[str, ndarray, DataFrame], index: Union[str, ndarray, DataFrame] = 'label', normalize: str = 'all') DataFrame#

Compute a simple cross-tabulation of two attributes.

Example

The following will compute the number of cells in each DNA clone and protein cluster.

>>> import missionbio.mosaic as ms
>>> sample = ms.load_example_dataset("2 PBMC mix")
>>> sample.dna.crosstab(sample.protein.get_labels())
Parameters:
columnsUnion[str, np.ndarray, pd.DataFrame]

Name of the row attribute or array of values to be used as columns. Uses get_attribute() constrained by row to retrieve the values.

indexUnion[str, np.ndarray, pd.DataFrame], default LABEL

Name of the row attribute or array of values to be used as index. Uses get_attribute() constrained by row to retrieve the values.

normalizebool, {‘all’, ‘index’, ‘columns’}, default: “all”

Normalize by dividing all values by the sum of values.

  • ‘all’ : normalize all values.

  • ‘index’ : normalize by the sum of values in the index.

  • ‘columns’ : normalize by the sum of values in the columns.

  • ‘off’ : no normalization.

Returns:
pd.DataFrame

A normalized cross-tabulation of two factors. It is an extension of pandas.crosstab() function for easy use with Mosaic.

Raises:
ValueError
  1. If the length of columns is not equal to the length of index.

  2. If the length of columns or index is greater than the number of cells

    when columns or index is a string.


< Class _Assay