![](/img/trans.png)
[英]How to output html table with merged cells from pandas DataFrame
[英]How to merge cells in the HTML output of a pandas dataframe in Python
這有點笨拙(當我解析 html 文本時)但可能適用於您的特定情況......
df = pd.DataFrame({
'col1': ['A', 'A', 'B', 'B'],
'col2': [1, 2, 3, 4],
'col3': [5, 6, 7, 8]})
df['cleanme'] = 'cleanme'
df = df.set_index(['col1', 'cleanme'])
html = df.to_html(index_names=False)
html = re.sub('<th></th>\n.*<th></th>', '<th>col1</th>', html) # notice your column name here
html = re.sub('<th>cleanme</th>', '', html)
with open('index.html', 'w') as fou:
fou.write(html)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.