使pandas数据框看起来更漂亮
pretty-html-table的Python项目详细描述
pretty_html_table-使漂亮的html表格变得简单
详细的使用文档仍在进行中 这个包的目标是将pandas数据框架转换成一个漂亮的html表。 截至目前,有10种颜色可供选择。这个包与其他用来发送电子邮件的包嵌入得非常好。 格式被设置为行项目,这样每个电子邮件提供者都可以理解它(而不是使用css样式)。
这是您可以在计算机上安装它的方法:
pip install pretty_html_table
例如,这就是如何转换数据帧:
import pretty_html_table
html_table_blue_light = build_table(pd.read_excel('df.xlsx'), 'blue_light')
print(html_table_blue_light)
为什么选择漂亮的HTML表?
它与其他用于发送电子邮件的python包集成得非常好。只需将此包的结果添加到电子邮件的正文中,然后瞧。
可用颜色列表
Name | font style | Header | Rows |
---|---|---|---|
'blue_light' | Century Gothic | Bold: yes / Background color: white / Font color: dark blue | Odd background color: light blue / Even background color: white |
blue_dark' | Century Gothic | Bold: yes / Background color: dark blue / Font color: white | Odd background color: light blue / Even background color: white |
grey_light' | Century Gothic | Bold: yes / Background color: white / Font color: dark grey | Odd background color: light grey / Even background color: white |
grey_dark' | Century Gothic | Bold: yes / Background color: dark grey / Font color: white | Odd background color: light grey / Even background color: white |
orange_light' | Century Gothic | Bold: yes / Background color: white / Font color: dark orange | Odd background color: light orange / Even background color: white |
orange_dark' | Century Gothic | Bold: yes / Background color: dark orange / Font color: white | Odd background color: light orange / Even background color: white |
yellow_light' | Century Gothic | Bold: yes / Background color: white / Font color: dark yellow | Odd background color: light yellow / Even background color: white |
yellow_dark' | Century Gothic | Bold: yes / Background color: dark yellow / Font color: white | Odd background color: light yellow / Even background color: white |
green_light' | Century Gothic | Bold: yes / Background color: white / Font color: dark green | Odd background color: light green / Even background color: white |
green_dark' | Century Gothic | Bold: yes / Background color: dark green / Font color: white | Odd background color: light green / Even background color: white |
与o365包集成的示例
首先,我们创建一个发送电子邮件的函数:
import O365
from O365 import Account
credentials = (o365credid, o365credpwd)
account = Account(credentials)
def send_email(account, to, subject, start, body, end):
m = account.new_message()
m.to.add(to)
m.subject = subject
m.body = start + body + end
m.send()
然后我们可以使用HTML语言编写电子邮件的开头和结尾:
start = """<html>
<body>
<strong>There should be an table here:</strong></br>"""
end = """</body>
</html>
"""
最后,我们可以使用漂亮的HTML包发送电子邮件:
import ph_table
html_table_blue_light = build_table(pd.read_excel('df.xlsx'), 'blue_light')
send_email(account
, 'test@any.com'
, 'test table'
, start
, html_table_blue_light
, end)
以下是所有当前可用的颜色: