Yian
Yian

Reputation: 169

Panda Python - Calculating what percentage of values are true and false out of total in boolean column

Hello I have a boolean value with True and False.

When I run a value_counts() like this

df['column'].value_counts()

I receive the following:

True     10718
False     1105
Name: column, dtype: int64

Is there a way to calculate what % of the total is true and what % is false?

Something like this:

True     91%
False    09%
Name: column, dtype: int64

Thank you

Upvotes: 6

Views: 10220

Answers (2)

BENY
BENY

Reputation: 323316

You can do with

df['yourcolumns'].value_counts(normalize=True).mul(100).astype(str)+'%'

Upvotes: 9

Yian
Yian

Reputation: 169

I was notified that it is as simple as

df['column'].value_counts(normalize=True)

Upvotes: 5

Related Questions