之前数据框的数据是通过计算得出的,有那种无限循环或者无限不循环小数,举个例子,原来是0.04599999,保留思四位小数后就是0.0460,在数据框的显示就是

因为是右对齐,所以看起来很方便,但是后在jupyter中的显示要去掉索引,所以就用了pandas包中的styler,这个包中还可以用CSS来更改显示,所以可以将pandas的索引不显示,但是这样就会是之前例子提到的0.0460,这个会变成0.046,数据框的显示是右对齐的,如果显示成0.046不是0.0460,那么右对齐就不好看了,就比如这种

想到的解决办法就是,在更改显示的style之前就讲这个数据框中的数字0.0460更改为字符串,之前是计算得到保留四位小数的数据,先在原始数据框添加一列字符串格式的,再将是float格式的那一列再删除,就可以用style了。还在考虑这种处理的弊端。

部分代码附上,之前的bin_woe_df的结果是一个数据框。

最后一行display是在from IPython.display import display

listwoestr=[]
        for i in range(len(bin_woe_df['woe'])):
            listwoestr.append('%.4f' % bin_woe_df['woe'][i])
        woestr=pd.DataFrame({'woestr':listwoestr,'woe':[bin_woe_df['woe'][i] for i in range(len(bin_woe_df['woe']))]})
        bin_woe_df=pd.merge(bin_woe_df,woestr,on='woe')
        bin_woe_df.loc[:,['woestr', 'woe']] = bin_woe_df.loc[:,['woe', 'woestr']].values
        bin_woe_df= bin_woe_df.drop('woestr', 1)
        with open ('out.html','w') as out:
            styler = bin_woe_df.style
            styler.set_table_styles([
                                   {'selector': '.row_heading',
                                    'props': [('display', 'none')]},
                                   {'selector': '.blank.level0',
                                    'props': [('display', 'none')]},         
                                   {'selector': 'td:nth-child(2)',
                                    'props': [('text-align', 'center')]}, 
                                   {'selector': 'td:nth-child(3)',
                                    'props': [('text-align', 'inherit')]},
                                   {'selector': 'td:nth-child(4)',
                                    'props': [('text-align', 'center')]},
                                   {'selector': 'td:nth-child(5)',
                                    'props': [('text-align', 'left')]}
                                   ])
        display(styler)

最后的结果就是这种,处于数据保密,我也不知道怎么展示。。

用styler更改样式后,解决数据框中数据无法保留四位小数相关推荐

  1. python解决数据框中添加一行或者一列(DataFrame的行列处理)

    1.解决数据框中添加一行(给定值) ###原数据框data_Peak_2 = pd.DataFrame({"Peak_density": np.ndarray.tolist(hma ...

  2. 熊猫数据集_处理熊猫数据框中的列表值

    熊猫数据集 Have you ever dealt with a dataset that required you to work with list values? If so, you will ...

  3. R语言数据框中的stringsAsFactors参数

    R语言数据框中的stringsAsFactors参数 数据框基本建立 参数:stringsAsFactors 数据框基本建立 (注:本文章中的Name变量区分大小写) Name <- c(&qu ...

  4. 在pandas数据框中选择多个列

    本文翻译自:Selecting multiple columns in a pandas dataframe I have data in different columns but I don't ...

  5. python 数据框缺失值_Python:处理数据框中的缺失值

    python 数据框缺失值 介绍 (Introduction) In the last article we went through on how to find the missing value ...

  6. Python:在Pandas数据框中查找缺失值

    How to find Missing values in a data frame using Python/Pandas 如何使用Python / Pandas查找数据框中的缺失值 介绍: (In ...

  7. python数据框去重_【Python】基于某些列删除数据框中的重复值

    Python按照某些列去重,可用drop_duplicates函数轻松处理.本文致力用简洁的语言介绍该函数. 一.drop_duplicates函数介绍 drop_duplicates函数可以按某列去 ...

  8. python绘制星空图_【Python】基于某些列删除数据框中的重复值

    阿黎逸阳 精选Python.SQL.R.MATLAB等相关知识,让你的学习和工作更出彩(可提供风控建模干货经验). Python按照 某些列去重 ,可用 drop_duplicates函数轻松处理 . ...

  9. python怎么索引txt数据中第四行_python-在熊猫数据框中按行计数编制索引

    我有一个带有两个元素的层次结构索引的"熊猫"数据框(" month"和" item_id").每行表示特定月份的特定项目,并具有用于关注多个 ...

  10. r中将数据框中数据类型转化_R中的数据类型

    r中将数据框中数据类型转化 Before we delve deeper into R programming, it is important to understand the various d ...

最新文章

  1. <utility><xutility>模板常见操作方法
  2. 线性代数 第一章 行列式
  3. 现在的人工智能逆天到什么地步了?
  4. 全志 增加强制横屏标志 Patch
  5. MySQL---第07章_单行函数
  6. C#基础(Day08)
  7. Linux:查看文件夹大小
  8. 在类库中使用Session
  9. maven 手动安装 ojdbc7
  10. JDK7升级到JDK8
  11. MFC项目使用Win7自带语音库(包含COM函数返回 “没有注册类”解决方式)
  12. apng2gif各种问题的解决
  13. Android开发初体验——创建一个简单的APP
  14. 移动端adaptive设置
  15. 华硕美版路由器RT-AC1200G+解决无线信号弱问题
  16. css实现tab切换时下划线动画效果
  17. 基于药效团的药物设计(Pharmacophore Construction)
  18. Sql Server 2000数据库日志日益庞大的解决方法
  19. 2021最新全球CS专业排名发布,CMU再夺榜首,清华和MIT并列第三!
  20. Android 单线程下载与多线程下载

热门文章

  1. Unbuntu更换阿里源
  2. 对比企业邮箱服务的好处
  3. 2006中国IT10大丑闻
  4. 2019.05 随笔
  5. PAT备考经验相关信息
  6. unity经营类游戏-植树造林-虚拟现实期末大作业
  7. [一起来做动图吧]Animate制作简单动图,包教包会,不会举报
  8. Koo叔说Shader-CG语言介绍
  9. 食堂报餐点餐公司订餐微信小程序源码开发使用
  10. 【Learning Notes】Sequence Transducer