pandas显示百分数,在pandas中将某些浮动数据框列设置为百分比

I am trying to write a paper in IPython notebook, but encountered some issues with display format. Say I have following dataframe df, is there any way to format var1 and var2 into 2 digit decimals and var3 into percentages.

var1 var2 var3

id

0 1.458315 1.500092 -0.005709

1 1.576704 1.608445 -0.005122

2 1.629253 1.652577 -0.004754

3 1.669331 1.685456 -0.003525

4 1.705139 1.712096 -0.003134

5 1.740447 1.741961 -0.001223

6 1.775980 1.770801 -0.001723

7 1.812037 1.799327 -0.002013

8 1.853130 1.822982 -0.001396

9 1.943985 1.868401 0.005732

The numbers inside are not multiplied by 100, e.g. -0.0057=-0.57%.

解决方案

replace the values using the round function, and format the string representation of the percentage numbers:

df['var2'] = pd.Series([round(val, 2)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值