转换浮点数的大 pandas 删除指数 [英] pandas converting a float remove exponents

查看:87
本文介绍了转换浮点数的大 pandas 删除指数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有如下数据:

Date            MBs     GBs
0   2018-08-14 20:10    32.00 MB    0.00 GB
1   2018-08-14 20:05    4.00 MB     0.00 GB
2   2018-08-14 20:00    1000.99 MB  1.23 GB

我通过以下操作剥离了MB和GB:

I stripped away the MB and GB by doing this:

df['MBs']=df['MB'].str.strip('MB')
df['GBs']=df['GB'].str.strip('GB')

然后将数字转换为浮点数并得到总计:

Then converted the number to a float and got the totals:

df['MBs'] = df['MBs'].astype('float')
df['GBs'] = df['MBs'].astype('float')

df.loc['Total', ['MBs', 'GBs']] = df.sum()

但是当我运行它时,我的数据具有指数

But when I run it my data has exponents

Date    Data Transferred (MB)   Data Transferred (GB)
146 2018-08-14 08:00:00 1.871237e+05    1.874017e+05
147 2018-08-14 07:55:00 1.123211e+05    1.961854e+05
148 2018-08-14 07:50:00 2.187703e+05    2.187123e+05
...
Total       1.408910e+08    1.408910e+08

如何将浮点型从指数型转换为普通型",只转换它,因为我需要获取总数

How do I convert change that float from exponent to "normal", im only converting it because I need to get the totals

推荐答案

您正尝试避免使用科学计数法:因此,您可以执行以下操作:

You are trying to avoid using scientific notation:So here is what you can do:

import pandas as pd
pd.set_option('display.float_format', lambda x: '%.3f' % x)

此行代码设置了熊猫的显示格式,因此不会使用科学概念

this line of code set the pandas display format so it will not use scientific notaion

参考: http://pandas.pydata. org/pandas-docs/stable/options.html?highlight = display%20float_format

这篇关于转换浮点数的大 pandas 删除指数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆