如何摆脱将excel表中的大数字转换为指数的 pandas ? [英] how to get rid of pandas converting large numbers in excel sheet to exponential?
问题描述
在excel表中,我有两列大数字.
In the excel sheet , i have two columns with large numbers.
但是当我使用 read_excel() 读取 excel 文件并显示数据框时,
But when i read the excel file with read_excel() and display the dataframe,
这两列以指数形式以科学格式打印.
those two columns are printed in scientific format with exponential.
怎样才能摆脱这种格式?
How can get rid of this format?
谢谢
熊猫输出
推荐答案
应用科学记数法的方式是通过 pandas 的显示控制的 选项:
The way scientific notation is applied is controled via pandas' display options:
pd.set_option('display.float_format', '{:.2f}'.format)
df = pd.DataFrame({'Traded Value':[67867869890077.96,78973434444543.44],
'Deals':[789797, 789878]})
print(df)
Traded Value Deals
0 67867869890077.96 789797
1 78973434444543.44 789878
如果这只是为了演示目的,您可以将您的将数据转换为字符串,同时逐列格式化它们:
If this is simply for presentational purposes, you may convert your data to strings while formatting them on a column-by-column basis:
df = pd.DataFrame({'Traded Value':[67867869890077.96,78973434444543.44],
'Deals':[789797, 789878]})
df
Deals Traded Value
0 789797 6.786787e+13
1 789878 7.897343e+13
df['Deals'] = df['Deals'].apply(lambda x: '{:d}'.format(x))
df['Traded Value'] = df['Traded Value'].apply(lambda x: '{:.2f}'.format(x))
df
Deals Traded Value
0 789797 67867869890077.96
1 789878 78973434444543.44
另一种更直接的方法是将以下行放在仅格式化浮点数的代码顶部:
An alternative more straightforward method would to put the following line at the top of your code that would format floats only:
pd.options.display.float_format = '{:.2f}'.format
这篇关于如何摆脱将excel表中的大数字转换为指数的 pandas ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!