Home > Mobile >  Transform decimal number to percentage and integer python
Transform decimal number to percentage and integer python

Time:11-18

I have a column that I need to transform its value to percentage.

example I have the value 0.166978 and I need to transform it into 16.70%

I did it as follows

df['EXAMPLE'] = df[['EXAMPLE']].applymap("{:.4f}%".format)

and got

0.1670%

How do I change these decimal places to get 16.70%

When I multiply by some value eg 10, 100 it looks like this 0.1670%0.1670%0.1670%0.1670%0.1670%0.1670%0.16...

CodePudding user response:

try this:

df['EXAMPLE'] = df['EXAMPLE'].apply(lambda row:"{:.2%}".format(float(row))

CodePudding user response:

Maybe you should try this :

df['EXAMPLE'] = (df['EXAMPLE']*100).apply(lambda r:"{:.2%}".format(r))
  • Related