tacco.utils.dataframe2anndata

dataframe2anndata(data, obs_key, var_key, count_key=None, compositional_keys=None, mean_keys=None)[source]

Creates an AnnData from a long form DataFrame. The entries of the .obs columns in the result AnnData are only well defined if they are identical per observation.

Parameters:
  • data – A DataFrame.

  • obs_key – The name of the column containing the categorical property to become the .obs dimension. Can also be a categorical Series compatible with data. If None, use the index as .obs dimension and keep all unused annotation in .obs.

  • var_key – The name of the column containing the categorical property to become the .var dimension. If None, the .var dimension will be of length 0.

  • count_key – The name of the column containing counts/weights to sum. If None, bare occurences (i.e. 1) are summed over.

  • compositional_keys – The names of the columns containing categorical properties to populate .obsm dataframes with.

  • mean_keys – The names of the columns containing numerical properties to construct mean quantities for .obs columns with.

Returns:

An AnnData containing the counts in .X.