pandas 小数位数 精度的处理方法

作者:小白的2015 时间:2022-12-16 20:40:05 

控制台打印时显示的2位小数:


pd.set_option('precision', 2)

实际修改数据精度:

官例:http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.round.html


>>> df = pd.DataFrame(np.random.random([3, 3]),
...  columns=['A', 'B', 'C'], index=['first', 'second', 'third'])
>>> df
   A   B   C
first 0.028208 0.992815 0.173891
second 0.038683 0.645646 0.577595
third 0.877076 0.149370 0.491027
>>> df.round(2)
  A  B  C
first 0.03 0.99 0.17
second 0.04 0.65 0.58
third 0.88 0.15 0.49
>>> df.round({'A': 1, 'C': 2})
  A   B  C
first 0.0 0.992815 0.17
second 0.0 0.645646 0.58
third 0.9 0.149370 0.49
>>> decimals = pd.Series([1, 0, 2], index=['A', 'B', 'C'])
>>> df.round(decimals)
  A B  C
first 0.0 1 0.17
second 0.0 1 0.58
third 0.9 0 0.49

来源:https://blog.csdn.net/baixiaozhe/article/details/54616041

标签:pandas,小数,位数,精度
0
投稿

猜你喜欢

  • python将.ppm格式图片转换成.jpg格式文件的方法

    2023-02-16 19:19:54
  • Python时间差中seconds和total_seconds的区别详解

    2022-10-04 15:00:49
  • Dlib+OpenCV深度学习人脸识别的方法示例

    2022-11-08 06:34:42
  • python实现马丁策略回测3000只股票的实例代码

    2023-03-02 01:12:29
  • python数据处理67个pandas函数总结看完就用

    2023-02-24 10:19:32
  • 微信小程序开发常见问题及解决方案

    2024-04-18 09:35:04
  • Django数据库连接丢失问题的解决方法

    2024-01-18 12:05:24
  • Python3 解决读取中文文件txt编码的问题

    2022-10-22 13:14:43
  • zabbix监控Nginx/Tomcat/MySQL的详细教程

    2024-01-15 04:31:33
  • 用Python解数独的方法示例

    2021-01-31 18:38:44
  • 请给PNG8一个机会:对png8的误解

    2009-09-21 10:45:00
  • 使用springboot通过spi机制加载mysql驱动的过程

    2024-01-27 09:12:26
  • SQL Server查询速度慢原因及优化方法

    2008-12-03 15:19:00
  • PyQt5每天必学之单行文本框

    2022-09-12 06:29:35
  • Python中的np.random.seed()随机数种子问题及解决方法

    2023-01-15 20:14:02
  • django 数据库返回queryset实现封装为字典

    2024-01-20 15:43:43
  • 编写SQL需要注意的细节Checklist总结

    2024-01-17 14:41:56
  • 后工业时代的后规范思考

    2009-06-03 20:30:00
  • python try except 捕获所有异常的实例

    2023-03-22 18:49:50
  • 浅谈Python peewee 使用经验

    2023-09-14 14:20:55
  • asp之家 网络编程 m.aspxhome.com