相关疑难解决方法(0)

Python有一个模块可以将CSS样式转换为电子邮件的内联样式吗?

我知道这存在于其他语言中,但我希望它能用于Python,我可以发送将在GMail等中显示的电子邮件.

css python

11
推荐指数
2
解决办法
5040
查看次数

pandas 数据框的颜色行并转换为 HTML 表

我正在尝试使用烧瓶显示熊猫数据框。我成功地这样做了,直到我决定为数据框的一些行着色。特别是当我应用to_html()熊猫的方法时我失败了。

以下代码获取一个表,其中一些行以黄色显示:

import pandas as pd
import numpy as np

np.random.seed(24)
df = pd.DataFrame({'A': np.linspace(1, 10, 10)})

df = pd.concat([df, pd.DataFrame(np.random.randn(10, 4), columns=list('BCDE'))],
               axis=1)
df.iloc[0, 2] = np.nan

def highlight_greaterthan(s,threshold,column):
    is_max = pd.Series(data=False, index=s.index)
    is_max[column] = s.loc[column] >= threshold
    return ['background-color: yellow' if is_max.any() else '' for v in is_max]


df = df.style.apply(highlight_greaterthan,threshold=1.0,column=['C','B'], axis=1)
display(df)
Run Code Online (Sandbox Code Playgroud)

接下来,当我运行to_html()它时,一切都崩溃了。

df_html = df.to_html

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-28-4d0cc094240b> in <module>()
----> 1 df_html = df.to_html

AttributeError: 'Styler' …
Run Code Online (Sandbox Code Playgroud)

html python pandas

9
推荐指数
1
解决办法
8671
查看次数

标签 统计

python ×2

css ×1

html ×1

pandas ×1