Use Series.value_counts
with normalize=True
, then multiple by 100
and change format to DataFrame
:
df1 = (df['age'].value_counts(normalize=True)
.mul(100)
.rename_axis('age')
.reset_index(name='percentage'))
print (df1)
age percentage
0 30-40 60.0
1 40-50 40.0
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…