pydit.wrangling.counts.count_values_in_col¶
- pydit.wrangling.counts.count_values_in_col(df_input, col, column_name=None, combined=True, percentage=False, detailed=False)[source]¶
Generates a column counting occurrence of values in a given column.
If several columns provided, it will generate a column for each of them, but if combined is True, it will generate a column counting unique combinations of values in the columns.
- Parameters:
df_input (pd.DataFrame) – Dataframe to be analyzed
col (str or list of str) – Name of the column containing values to tally
column_name (str or list of str, optional, default None) – Name of the columns to be created containing the count of values If None, the column name will be “count_[col]”.
combined (bool, optional, default True) – Whether or not compute the counts combining all the columns provided
percentage (bool, optional, default False) – Whether to return percentage over total count
detailed (bool, optional, default False) – Whether to return only the combined count and drop the extra details
- Returns:
New dataframe with a new column containing the count of values
- Return type:
pd.DataFrame