久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

格式化/抑制 Python Pandas 聚合結果的科學記數法

Format / Suppress Scientific Notation from Python Pandas Aggregation Results(格式化/抑制 Python Pandas 聚合結果的科學記數法)
本文介紹了格式化/抑制 Python Pandas 聚合結果的科學記數法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

如何修改 pandas 中的 groupby 操作的輸出格式,該操作為非常大的數字生成科學記數法?

How can one modify the format for the output from a groupby operation in pandas that produces scientific notation for very large numbers?

我知道如何在 python 中進行字符串格式化,但是在這里應用它時我不知所措.

I know how to do string formatting in python but I'm at a loss when it comes to applying it here.

df1.groupby('dept')['data1'].sum()

dept
value1       1.192433e+08
value2       1.293066e+08
value3       1.077142e+08

如果我轉換為字符串,這會抑制科學記數法,但現在我只是想知道如何格式化字符串和添加小數.

This suppresses the scientific notation if I convert to string but now I'm just wondering how to string format and add decimals.

sum_sales_dept.astype(str)

推薦答案

當然,我在評論中鏈接的答案不是很有幫助.您可以像這樣指定自己的字符串轉換器.

Granted, the answer I linked in the comments is not very helpful. You can specify your own string converter like so.

In [25]: pd.set_option('display.float_format', lambda x: '%.3f' % x)

In [28]: Series(np.random.randn(3))*1000000000
Out[28]: 
0    -757322420.605
1   -1436160588.997
2   -1235116117.064
dtype: float64

我不確定這是否是首選方法,但它確實有效.

I'm not sure if that's the preferred way to do this, but it works.

純粹出于審美目的將數字轉換為字符串似乎是個壞主意,但如果你有充分的理由,這是一種方法:

Converting numbers to strings purely for aesthetic purposes seems like a bad idea, but if you have a good reason, this is one way:

In [6]: Series(np.random.randn(3)).apply(lambda x: '%.3f' % x)
Out[6]: 
0     0.026
1    -0.482
2    -0.694
dtype: object

這篇關于格式化/抑制 Python Pandas 聚合結果的科學記數法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Python 3 Float Decimal Points/Precision(Python 3 浮點小數點/精度)
Converting Float to Dollars and Cents(將浮點數轉換為美元和美分)
What are some possible calculations with numpy or scipy that can return a NaN?(numpy 或 scipy 有哪些可能的計算可以返回 NaN?)
Python float to ratio(Python浮動比率)
How to manage division of huge numbers in Python?(如何在 Python 中管理大量數字的除法?)
mean from pandas and numpy differ(pandas 和 numpy 的意思不同)
主站蜘蛛池模板: 国产福利91精品一区二区三区 | 免费看国产精品视频 | 久久美女网 | 欧美久久久久久久 | 午夜在线 | av中文字幕在线观看 | 天天插天天狠天天透 | 中文字幕在线人 | 国产免费麻豆视频 | 国产精品人人做人人爽 | 中文字幕一区二区在线观看 | 欧美成人激情 | 青青久久av北条麻妃海外网 | 亚洲高清视频在线观看 | 成人激情视频在线播放 | 亚洲美女一区二区三区 | 国产精品久久久久一区二区 | 日韩综合一区 | 亚洲欧美国产毛片在线 | 成人亚洲一区 | 日韩欧美在线观看视频网站 | 99爱在线| 国产伦精品一区二区三区照片91 | 国产精品久久99 | 国产激情视频在线免费观看 | 中文字幕在线观看 | 久久久人| 中文字幕1区| 国产片一区二区三区 | 黄色电影在线免费观看 | 亚洲精品一| 一区二区三区四区电影 | 国产高清一区二区三区 | 日韩欧美精品一区 | 国产精品成人一区二区 | 综合九九 | 国产剧情一区 | 国产乱精品一区二区三区 | 久久人| 琪琪午夜伦伦电影福利片 | 激情一区|