pandasdataframesyntaxpercentage

Is there a way I can add a % sign to my results


I am currently calculating percentages for my data set:

How can I add the % symbol at the end of the numbers?

round((df.value_counts('label')/df.value_counts('label').sum()) * 100)

results:

label
retained    82.0
churned     18.0
dtype: float64

I am expecting to see % at the end of 82 and 18.


Solution

  • try:

    round((df.value_counts('label') / df.value_counts('label').sum()) * 100).astype(str) + '%'