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

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

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

Here is what the above code is Doing:
1. We are using the value_counts() method to count the number of times each value appears in the column.
2. We are using the normalize parameter to get the relative frequency of each value.
3. We are using the mul() method to multiply the relative frequency by 100 to get the percentage.
4. We are using the astype() method to convert the result to a string.
5. We are using the add() method to add the % sign to the end of each value.

Similar Posts