Data Science · Level 2 Aggregation

pandas value_counts

Count how often each browser, plan or answer appears with value_counts(), and turn the counts into percentages.

  • value_counts() sorts by count
  • normalize=True gives shares
  • dropna=False keeps missing values

value_counts() counts each distinct value, most frequent first, and normalize=True gives shares instead. Trap: missing values are left out of the total unless you pass dropna=False.

plans = pd.Series(["free", "pro", "free", None])
plans.value_counts()                 # free 2, pro 1
plans.value_counts(normalize=True)   # free 0.667, pro 0.333
plans.value_counts(normalize=True, dropna=False)   # free 0.5 ...

Write top_share(s) that returns the most common value and its percentage of all answers, missing ones included, rounded to 1 decimal, for example pd.Series(["a", "b", "a"]) gives ('a', 66.7).

solution.py
Test Suites Pending
Output