Python 3.x 从dataframe生成html
对不起,我是通过熊猫处理html的新手,在生成所需格式时遇到问题 我有如下的数据帧Python 3.x 从dataframe生成html,python-3.x,pandas,dataframe,pandas-styles,Python 3.x,Pandas,Dataframe,Pandas Styles,对不起,我是通过熊猫处理html的新手,在生成所需格式时遇到问题 我有如下的数据帧 Category Date Avg Price - growth (%) Profit Overall profit A 4/18/2021 34.30% 706.10% 669.60% B 4/18/2021 97.40% 1994.60% 1879.
Category Date Avg Price - growth (%) Profit Overall profit
A 4/18/2021 34.30% 706.10% 669.60%
B 4/18/2021 97.40% 1994.60% 1879.00%
C 4/18/2021 742.00% 223.60% -482.60%
我需要为电子邮件生成如下html(我还使用df.styleing选项格式化其中一些字段和
因此,我需要进行两项更改:
[3] :它们似乎相同,但有点不同要构建数据结构,您可以尝试以下方法
>>> df.groupby(['Date','Category']).sum().unstack('Category').swaplevel(0,1,axis=1).sort_index(axis=1)
Category A B C
AVG_Price Overall_profit Profit AVG_Price Overall_profit Profit AVG_Price Overall_profit Profit
Date
4/18/2021 34.30% 669.60% 706.10% 97.40% 1879.00% 1994.60% 742.00% -482.60% 223.60%
要将其转换为html,您只需将添加到_html()
,但这不会给您提供所需的标题(总体增长报告)
获得选举权