日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python修改html表格,使用styles和css更改pandas dataframe html表python中...

發布時間:2023/12/10 python 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python修改html表格,使用styles和css更改pandas dataframe html表python中... 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

這需要幾個步驟:

首先導入HTML并重新輸入

from IPython.display import HTML

import re

你可以通過to_html方法得到html pandas.

df_html = df.to_html()

接下來,我們將為html表和我們要創建的樣式生成隨機標識符.

random_id = 'id%d' % np.random.choice(np.arange(1000000))

因為我們要插入一些樣式,所以我們需要注意指定此樣式僅適用于我們的表.現在讓我們將其插入到df_html中

df_html = re.sub(r'

并創建一個樣式標記.這真的取決于你.我剛添加了一些懸停效果.

style = """

table#{random_id} tr:hover {{background-color: #f5f5f5}}

""".format(random_id=random_id)

最后,顯示它

HTML(style + df_html)

功能齊全.

def HTML_with_style(df, style=None, random_id=None):

from IPython.display import HTML

import numpy as np

import re

df_html = df.to_html()

if random_id is None:

random_id = 'id%d' % np.random.choice(np.arange(1000000))

if style is None:

style = """

table#{random_id} {{color: blue}}

""".format(random_id=random_id)

else:

new_style = []

s = re.sub(r'?style>', '', style).strip()

for line in s.split('\n'):

line = line.strip()

if not re.match(r'^table', line):

line = re.sub(r'^', 'table ', line)

new_style.append(line)

new_style = ['']

style = re.sub(r'table(#\S+)?', 'table#%s' % random_id, '\n'.join(new_style))

df_html = re.sub(r'

return HTML(style + df_html)

像這樣使用它:

HTML_with_style(df.head())

HTML_with_style(df.head(), '')

style = """

tr:nth-child(even) {color: green;}

tr:nth-child(odd) {color: aqua;}

"""

HTML_with_style(df.head(), style)

學習CSS并瘋狂!

總結

以上是生活随笔為你收集整理的python修改html表格,使用styles和css更改pandas dataframe html表python中...的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。