Python Pandas-数据框中的数字列为指数数 [英] Python pandas - Numeric column in dataframe is in exponent number

查看:347
本文介绍了Python Pandas-数据框中的数字列为指数数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始遇到这个问题,在该列中,很少有指数形式的值,而其余的是正数.

I've recently started facing this problem where in a column few values are in Exponential form and rest are regular numbers.

我想合并两列,但是对于指数形式的那一列不会产生任何结果.我想如何克服这个问题来合并2个数据框.

I want to merge two columns but it is not yielding any result for the one in exponent form. I would like to how can I overcome this problem to merge 2 dataframes.

示例

df1
2780989
2780749
2816256

df2
2780989
2780749
2.81625e+06

pd.merge(df1,df2, on = 'column1')
2780989
2780749

我尝试更改字符串中的两列,然后要么显示

I tried changing both columns in strings then it is either showing

2780989.0
2780749.0
2816256.0

我有一种解决方法,将要合并的列保留为df中的第一列,但是如果它位于第二位置,它将开始显示如上所述的值.

I have a workaround which is keeping the column I want to merge as the very first column in my df but if it is on 2nd position it will start showing values as I mentioned above.

推荐答案

让我们将两个数据帧都转换为float:

Let's convert both dataframes to float:

df1 = pd.DataFrame({'Col1':[2780989,2780749,2816250]}, dtype='int')

df2 = pd.DataFrame({'Col1':['2780989','2780749','2.81625e+06']})

pd.merge(df1.astype(float),df2.astype(float), on='Col1')

输出:

        Col1
0  2780989.0
1  2780749.0
2  2816250.0

这篇关于Python Pandas-数据框中的数字列为指数数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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