Skip to content

ENH: add value_counts_with_normalization #62377

@dont-4get-me-men

Description

@dont-4get-me-men

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

I wish i could write one function which will create view for normalizied data and non-normalized data while calliing thi function.

Feature Description

i see this function in this way

def value_counts_with_normalization(self, subset=None,sort=True, ascending=False, dropna=True,percentage = False):
    ----
    non_normalized_df = self.value_counts(subset = subset
                 ,sort = True,ascending=ascending
                ,dropna = dropna, normalization = False).reset_index()
   
    normalized_df = self.value_counts(subset = subset,sort = True,ascending=ascending,dropna = dropna, normalization = False).reset_index()
    multiplier = 100 if percentage else 1
    normalized_df['proportion'] = normalized_df['proportion']*multiplier
return non_normalized_df.merge(normalized_df , on = subset)

Alternative Solutions

I couln't find alternative solution

Additional Context

Example of output

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignAlgosNon-arithmetic algos: value_counts, factorize, sorting, isin, clip, shift, diffClosing CandidateMay be closeable, needs more eyeballsEnhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions