Pandas percentage by value in a column

后端 未结 5 1936
死守一世寂寞
死守一世寂寞 2020-12-03 06:17

I want to get a percentage of a particular value in a df column. Say I have a df with (col1, col2 , col3, gender) gender column has values of M or F. I want to get the perc

5条回答
  •  既然无缘
    2020-12-03 07:17

    Use value_counts with normalize=True:

    df['gender'].value_counts(normalize=True) * 100
    

提交回复
热议问题