percentage true in pandas series code example
Example: percentage true in pandas series
truths = pd.Series([True, False, False, True, True])
# With only booleans, use that True => 1 and False => 0
percent_true = truths.mean() #==> 0.6
percent_false = 1 - percent_true #==> 0.4
# Generalising to all values, but slower with just booleans
percent_series = truths.value_counts(normalize=True)
#==> pd.Series (
# True 0.6
# False 0.4
# dtype: float64
# )
# First: https://stackoverflow.com/a/52438477/
# Second: https://stackoverflow.com/a/52229939/