0

with the df['goal'].value_counts():

The result is:

0   1000
1    500

Is there a fast way to also get the percentage of with class like:

0 1000 66,7%
1  500 33,3%
Katty_one
  • 351
  • 1
  • 8
  • 1
    try this: `df['percentage'] = df.apply(lambda x: x / x.sum(axis=0));df['percentage'] = df['percentage'].map('{:.2%}'.format)` – r-beginners Nov 07 '21 at 02:47
  • 1
    [`value_counts`](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.value_counts.html) has a normalize parameter. `df['goal'].value_counts(normalize=True)` [this answer](https://stackoverflow.com/a/58434981/15497888) in the linked duplicate extends this to include the multiply round and add percentage. – Henry Ecker Nov 07 '21 at 02:53

0 Answers0