简体   繁体   English

将科学计数法转换为小数熊猫python

[英]convert scientific notation to decimal pandas python

Probably it is an old question, I found the similar questions below but I still can see the scientific notation in my output file. 可能这是一个老问题,我在下面找到了类似的问题,但是我仍然可以在输出文件中看到科学符号。

Suppressing scientific notation in pandas? 抑制大熊猫的科学计数法吗?

Pandas read scientific notation and change 熊猫阅读科学符号和变化

Python Pandas Scientific Notation Iconsistent Python Pandas科学符号图标

I have tried to incorporate set_option and df.apply(pd.to_numeric, args=('coerce',)) etc to my code below while do not work. 我试图将set_optiondf.apply(pd.to_numeric, args=('coerce',))等合并到下面的代码中,但不起作用。

df = pd.read_csv(Input)  

dfNew = df[['co_A','co_B','co_C']]  
# I firstly select columns from df then would like to convert scientific notation to decimal type in my output file.

dfNew.to_csv(Output, index = False, sep = '\t')

Still I can see scientific notation in my output file. 仍然可以在输出文件中看到科学计数法。 Anyone can help? 有人可以帮忙吗?

co_A  co_B  co_C
167 0.0 59.6
168 0.0 60.6
191 8e-09   72.6
197 -4.7718e-06 12.3
197 0.0 92.4
198 0.0 39.5

you can use float_format parameter when calling .to_csv() function: 您可以在调用.to_csv()函数时使用float_format参数:

In [207]: df
Out[207]:
   co_A          co_B  co_C
0   167  0.000000e+00  59.6
1   168  0.000000e+00  60.6
2   191  8.000000e-09  72.6
3   197 -4.771800e-06  12.3
4   197  0.000000e+00  92.4
5   198  0.000000e+00  39.5

In [208]: fn = r'D:\temp\.data\out.csv'

In [209]: df.to_csv(fn, index=False, sep='\t', float_format='%.6f')

out.csv: out.csv:

co_A    co_B    co_C
167 0.000000    59.600000
168 0.000000    60.600000
191 0.000000    72.600000
197 -0.000005   12.300000
197 0.000000    92.400000
198 0.000000    39.500000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM