简体   繁体   English

如何在表格中进行良好的可视化?

[英]How to make a good visualization in a table?

The code below creates a table of news and sends this via Mail to recipients.下面的代码创建了一个新闻表,并通过邮件将其发送给收件人。 The output (the table in the mail) looks very bad so it is not designed and there is a column that shows the number of the rows. output(邮件中的表格)看起来很糟糕,所以它不是设计的,并且有一列显示行数。

Is there any possibility to delete this column and design the table a bit more beautiful like a striped table with blue and white?有没有可能删掉这一栏,把桌子设计得更漂亮一点,像蓝白条纹的桌子?

import csv, ssl
import smtplib
from GoogleNews import GoogleNews

ssl._create_default_https_context = ssl._create_unverified_context

googlenews = GoogleNews()
googlenews.set_encode('utf_8')
googlenews.set_lang('en')
googlenews.set_period('7d')
googlenews.get_news("New York")
keys = googlenews.results()[0].keys()
table = []

for row in googlenews.results():
    table.append({'Titel': row['title'], 'Datum': row['date'], 'URL': row['link'], 
                  'Quelle': row['site']})

import cred
import pandas as pd
from email.message import EmailMessage
df = pd.DataFrame(table)

from_mail = "example@gmail.com"
from_password = cred.passwort
to_mail = ['example@hotmail.com']
smtp_server = "smtp.gmail.com"
smtp_port = 465

def send_email(smtp_server, smtp_port, from_mail, from_password, to_mail):
    '''
        Send results via mail
    '''

    msg = EmailMessage()
    msg['Subject'] = 'News'
    msg['From'] = from_mail
    msg['To'] = ', '.join(to_mail + [from_mail])

    html = """\
    <html>
    <head></head>
    <body>
    {0}
    </body>
    </html>
    """.format(df.to_html())
    msg.set_content(html, 'html')

    with smtplib.SMTP_SSL(smtp_server, smtp_port) as server:
        server.ehlo()
        server.login(from_mail, from_password)
        server.send_message(msg)
        server.quit()

send_email(smtp_server, smtp_port, from_mail, from_password, to_mail)

One way to make HTML better looking is CSS.使 HTML 更好看的一种方法是 CSS。 CSS is a language used for styling HTML. CSS 是一种用于造型 HTML 的语言。 It can be used to adjust add colors, borders, outlines, and more to HTML.它可用于调整添加 colors、边框、轮廓等到 HTML。 You can add global CSS in your <head> section with the <style> tag, or apply it to individual tags with the style attribute.您可以使用<style>标记在<head>部分中添加全局 CSS,或将其应用于具有style属性的单个标记。
If you want to learn about CSS, I would recommend W3 schools' CSS tutorial.如果你想了解 CSS,我会推荐W3 学校的CSS 教程。
I know this is not a copy and paste answer, but I am not an expert at CSS myself.我知道这不是复制和粘贴的答案,但我本人不是 CSS 的专家。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM