代码之家  ›  专栏  ›  技术社区  ›  thomas.mac

无论如何保存pandas styler对象

  •  3
  • thomas.mac  · 技术社区  · 7 年前

    这是一个具有背景渐变的styler对象:

    enter image description here

    我只是想把它保存下来。已尝试使用。render(),但不确定该如何处理HTML代码,从阅读有关该主题的其他问题来看,似乎目前没有保存这些问题的方法。有没有黑客的方法?

    以下是阵列:

    array([[ 0.264     ,  0.271     ,  0.285     ,  0.289     ,  0.329     ],
       [ 0.053     ,  0.051     ,  0.045     ,  0.038     ,  0.031     ],
       [ 0.006     ,  0.007     ,  0.009     ,  0.01      ,  0.01      ],
       [-3.98650106, -3.95728537, -3.99767582, -4.20624136, -3.54186842],
       [-3.22600677, -2.87623307, -2.03420988, -1.54443176, -1.41006671]])
    

    我有一行代码:

    df.style.background_gradient(cmap='RdYlGn',low=.09,high=.18,axis=1)
    
    1 回复  |  直到 3 年前
        1
  •  6
  •   MaxU - stand with Ukraine    7 年前

    从Pandas 0.20.0开始,您可以轻松地将其保存到Excel文件:

     df.style.background_gradient(cmap='RdYlGn',low=.09,high=.18,axis=1) \
       .to_excel('d:/temp/a.xlsx', engine='openpyxl')
    

    结果:

    enter image description here

    推荐文章