我正在尝试使用pandas数据帧用python自动发送电子邮件(包含tabled)。当我为表格生成一个HTML并用浏览器打开它时,一切都很好。当我试图在电子邮件中呈现相同的html时,一些数据丢失了。你知道吗
浏览器中呈现的HTML
电子邮件中呈现的HTML
这是我用来创建HTML的代码-def csvToJinjaHTML(csvContent):
print("Pandas: Set the max_colwidth to -1 for unlimited string length")
pd.set_option("display.max_colwidth",-1)
print("Pandas: Create a Pandas table from CSV content")
pandasTable = pd.read_csv(StringIO(csvContent), index_col=False)
# pandasTable is the dataframe that we want to beautify
print(pandasTable)
stylerObject = pandasTable.style
styledHTML = (stylerObject
.set_table_attributes('border="1" class="dataframe table table-hover table-bordered"')
.set_properties(**{'font-size': '16pt', 'font-family': 'Calibri'})
# .set_properties(subset=['6', '5'], **{'width': '300px'})
.applymap(colour, subset=['ORGANIZATION'])
.set_precision(3)
.set_table_styles(
[{'selector': 'tr:nth-of-type(odd)',
'props': [('background', '#eee')]},
{'selector': 'tr:nth-of-type(even)',
'props': [('background', 'white')]},
{'selector': 'th',
'props': [('background', '#606060'),
('color', 'white'),
('font-family', 'verdana')]},
{'selector': 'td',
'props': [('font-family', 'verdana')]},
]
).hide_index()
.render()
)
with open('myJinjaTable.html', 'w') as f:
print("Writing an HTML file to view the beautified Jinja table")
f.write(styledHTML)
return styledHTML