spac.data_utils.bin2cat(data, one_hot_annotations, new_annotation)[source]

Combine a set of columns representing a binary one hot encoding of categories into a new categorical column.

Parameters:
  • data (pandas.DataFrame) – The pandas dataframe containing the one hot encoded annotations.

  • one_hot_annotations (str or list of str) – A string or a list of strings representing python regular expression of the one hot encoded annotations columns in the data frame.

  • new_annotation (str) – The column name for new categorical annotation to be created.

Returns:

  • pandas.DataFrame – DataFrame with new categorical column added.

  • Example

  • ——–

  • >>> data = pd.DataFrame({

  • … ‘A’ ([1, 1, 0, 0],)

  • … ‘B’ ([0, 0, 1, 0])

  • … })

  • >>> one_hot_annotations = [‘A’, ‘B’]

  • >>> new_annotation = ‘new_category’

  • >>> result = bin2cat(data, one_hot_annotations, new_annotation)

  • >>> print(result[new_annotation])

  • 0 A

  • 1 A

  • 2 B

  • 3 NaN

  • Name (new_category, dtype: object)