熊猫风格的表托管在图图中
晚上好,
我用脚注从SQL查询中创建了“几个”样式的数据帧表,并想创建一个子图形图,以报表格式托管这些表。
表代码如下:
sql_query = pd.read_sql_query (sqlq, connection)
df = sql_query
df['Product_Group'].loc[df['Product_Group'] == 'Pizzas'] = '*Pizzas'
df['Product_Group'].loc[df['Product_Group'] == 'Tratorria'] = '**Tratorria'
df['Price'] = df['Price'].apply(lambda x : '{:,}'.format(x))+ ' EGP';
df['Quantity'] = df['Quantity'].apply(lambda x : "{:,}".format(x))+ ' Units';
df = df.style.set_caption((
f'''Quantity and Sales broken down by <u>Product Group</u>.<br>
The data is filtered on <u>Order Date</u> and <u>Branch Name</u>.<br>
The Branch Name filter keeps <strong>{branch[2]}</strong>.<br>
* Pizzas Includes: <strong>(Pizza Meat,Pizza Vegetables, Pizza Turkey, Pizza Seafood, Appetizers)</strong><br>
** Trattoria Includes: <strong>(Pasta,Risotto)</strong>'''
))
dfstyle = [dict(selector="th", props=[('font-size', '18px')]),\
dict(selector="td", props=[('font-size', '16px')]),\
dict(selector="caption",props=[("text-align", "left"),("caption-side", "bottom"),
("font-size", "14px"),("color", 'black')]
)
]
df = df.set_table_styles(dfstyle)
df = df.apply(bold_lastrow)
df = df.set_properties(subset=['Quantity','Price'], **{'width': '400px'})
df = df.set_properties(subset=['Product_Group'], **{'text-align': 'left','font-weight': 'bold'})
df = df.set_properties(**{'font-family': 'Century Gothic'})
df = df.hide_index()
html渲染以重新创建表:
'<style type="text/css" >\n #T_04faa_ th {\n font-size: 18px;\n } #T_04faa_ td {\n font-size: 16px;\n } #T_04faa_ caption {\n text-align: left;\n caption-side: bottom;\n font-size: 14px;\n color: black;\n }#T_04faa_row0_col0,#T_04faa_row1_col0,#T_04faa_row2_col0,#T_04faa_row3_col0,#T_04faa_row4_col0{\n text-align: left;\n font-weight: bold;\n font-family: Century Gothic;\n }#T_04faa_row0_col1,#T_04faa_row0_col2,#T_04faa_row1_col1,#T_04faa_row1_col2,#T_04faa_row2_col1,#T_04faa_row2_col2,#T_04faa_row3_col1,#T_04faa_row3_col2,#T_04faa_row4_col1,#T_04faa_row4_col2{\n width: 400px;\n font-family: Century Gothic;\n }#T_04faa_row5_col0{\n font-weight: bold;\n text-align: left;\n font-weight: bold;\n font-family: Century Gothic;\n }#T_04faa_row5_col1,#T_04faa_row5_col2{\n font-weight: bold;\n width: 400px;\n font-family: Century Gothic;\n }</style><table id="T_04faa_" ><caption>Quantity and Sales broken down by <u>Product Group</u>.<br>\n The data is filtered on <u>Order Date</u> and <u>Branch Name</u>.<br>\n The Branch Name filter keeps <strong>All Branches</strong>.<br>\n * Pizzas Includes: <strong>(Pizza Meat,Pizza Vegetables, Pizza Turkey, Pizza Seafood, Appetizers)</strong><br>\n ** Trattoria Includes: <strong>(Pasta,Risotto)</strong></caption><thead> <tr> <th class="col_heading level0 col0" >Product_Group</th> <th class="col_heading level0 col1" >Quantity</th> <th class="col_heading level0 col2" >Price</th> </tr></thead><tbody>\n <tr>\n <td id="T_04faa_row0_col0" class="data row0 col0" >None</td>\n <td id="T_04faa_row0_col1" class="data row0 col1" >10.0 Units</td>\n <td id="T_04faa_row0_col2" class="data row0 col2" >250.0 EGP</td>\n </tr>\n <tr>\n <td id="T_04faa_row1_col0" class="data row1 col0" >Beverages</td>\n <td id="T_04faa_row1_col1" class="data row1 col1" >301.0 Units</td>\n <td id="T_04faa_row1_col2" class="data row1 col2" >10,214.0 EGP</td>\n </tr>\n <tr>\n <td id="T_04faa_row2_col0" class="data row2 col0" >Others</td>\n <td id="T_04faa_row2_col1" class="data row2 col1" >95.0 Units</td>\n <td id="T_04faa_row2_col2" class="data row2 col2" >7,315.0 EGP</td>\n </tr>\n <tr>\n <td id="T_04faa_row3_col0" class="data row3 col0" >*Pizzas</td>\n <td id="T_04faa_row3_col1" class="data row3 col1" >144.0 Units</td>\n <td id="T_04faa_row3_col2" class="data row3 col2" >20,830.0 EGP</td>\n </tr>\n <tr>\n <td id="T_04faa_row4_col0" class="data row4 col0" >**Tratorria</td>\n <td id="T_04faa_row4_col1" class="data row4 col1" >43.0 Units</td>\n <td id="T_04faa_row4_col2" class="data row4 col2" >6,715.0 EGP</td>\n </tr>\n <tr>\n <td id="T_04faa_row5_col0" class="data row5 col0" >Grand Total</td>\n <td id="T_04faa_row5_col1" class="data row5 col1" >593.0 Units</td>\n <td id="T_04faa_row5_col2" class="data row5 col2" >45,324.0 EGP</td>\n </tr>\n </tbody></table>'
但是我仍然不知道如何在子图数字中托管此“造型对象”以将其导出为A4报告。
编辑2:
jupyter呈现样式的DF如下:
但是,html html df.render()显示df如下:
从继续进行嵌入输出HTML的研究以渲染报告。
Good evening,
I created "Several" styled DataFrame tables from SQL query with footnotes and would like to create a subplot figure to host these tables in a report format.
Table Code is as follows:
sql_query = pd.read_sql_query (sqlq, connection)
df = sql_query
df['Product_Group'].loc[df['Product_Group'] == 'Pizzas'] = '*Pizzas'
df['Product_Group'].loc[df['Product_Group'] == 'Tratorria'] = '**Tratorria'
df['Price'] = df['Price'].apply(lambda x : '{:,}'.format(x))+ ' EGP';
df['Quantity'] = df['Quantity'].apply(lambda x : "{:,}".format(x))+ ' Units';
df = df.style.set_caption((
f'''Quantity and Sales broken down by <u>Product Group</u>.<br>
The data is filtered on <u>Order Date</u> and <u>Branch Name</u>.<br>
The Branch Name filter keeps <strong>{branch[2]}</strong>.<br>
* Pizzas Includes: <strong>(Pizza Meat,Pizza Vegetables, Pizza Turkey, Pizza Seafood, Appetizers)</strong><br>
** Trattoria Includes: <strong>(Pasta,Risotto)</strong>'''
))
dfstyle = [dict(selector="th", props=[('font-size', '18px')]),\
dict(selector="td", props=[('font-size', '16px')]),\
dict(selector="caption",props=[("text-align", "left"),("caption-side", "bottom"),
("font-size", "14px"),("color", 'black')]
)
]
df = df.set_table_styles(dfstyle)
df = df.apply(bold_lastrow)
df = df.set_properties(subset=['Quantity','Price'], **{'width': '400px'})
df = df.set_properties(subset=['Product_Group'], **{'text-align': 'left','font-weight': 'bold'})
df = df.set_properties(**{'font-family': 'Century Gothic'})
df = df.hide_index()
HTML Render to recreate table:
'<style type="text/css" >\n #T_04faa_ th {\n font-size: 18px;\n } #T_04faa_ td {\n font-size: 16px;\n } #T_04faa_ caption {\n text-align: left;\n caption-side: bottom;\n font-size: 14px;\n color: black;\n }#T_04faa_row0_col0,#T_04faa_row1_col0,#T_04faa_row2_col0,#T_04faa_row3_col0,#T_04faa_row4_col0{\n text-align: left;\n font-weight: bold;\n font-family: Century Gothic;\n }#T_04faa_row0_col1,#T_04faa_row0_col2,#T_04faa_row1_col1,#T_04faa_row1_col2,#T_04faa_row2_col1,#T_04faa_row2_col2,#T_04faa_row3_col1,#T_04faa_row3_col2,#T_04faa_row4_col1,#T_04faa_row4_col2{\n width: 400px;\n font-family: Century Gothic;\n }#T_04faa_row5_col0{\n font-weight: bold;\n text-align: left;\n font-weight: bold;\n font-family: Century Gothic;\n }#T_04faa_row5_col1,#T_04faa_row5_col2{\n font-weight: bold;\n width: 400px;\n font-family: Century Gothic;\n }</style><table id="T_04faa_" ><caption>Quantity and Sales broken down by <u>Product Group</u>.<br>\n The data is filtered on <u>Order Date</u> and <u>Branch Name</u>.<br>\n The Branch Name filter keeps <strong>All Branches</strong>.<br>\n * Pizzas Includes: <strong>(Pizza Meat,Pizza Vegetables, Pizza Turkey, Pizza Seafood, Appetizers)</strong><br>\n ** Trattoria Includes: <strong>(Pasta,Risotto)</strong></caption><thead> <tr> <th class="col_heading level0 col0" >Product_Group</th> <th class="col_heading level0 col1" >Quantity</th> <th class="col_heading level0 col2" >Price</th> </tr></thead><tbody>\n <tr>\n <td id="T_04faa_row0_col0" class="data row0 col0" >None</td>\n <td id="T_04faa_row0_col1" class="data row0 col1" >10.0 Units</td>\n <td id="T_04faa_row0_col2" class="data row0 col2" >250.0 EGP</td>\n </tr>\n <tr>\n <td id="T_04faa_row1_col0" class="data row1 col0" >Beverages</td>\n <td id="T_04faa_row1_col1" class="data row1 col1" >301.0 Units</td>\n <td id="T_04faa_row1_col2" class="data row1 col2" >10,214.0 EGP</td>\n </tr>\n <tr>\n <td id="T_04faa_row2_col0" class="data row2 col0" >Others</td>\n <td id="T_04faa_row2_col1" class="data row2 col1" >95.0 Units</td>\n <td id="T_04faa_row2_col2" class="data row2 col2" >7,315.0 EGP</td>\n </tr>\n <tr>\n <td id="T_04faa_row3_col0" class="data row3 col0" >*Pizzas</td>\n <td id="T_04faa_row3_col1" class="data row3 col1" >144.0 Units</td>\n <td id="T_04faa_row3_col2" class="data row3 col2" >20,830.0 EGP</td>\n </tr>\n <tr>\n <td id="T_04faa_row4_col0" class="data row4 col0" >**Tratorria</td>\n <td id="T_04faa_row4_col1" class="data row4 col1" >43.0 Units</td>\n <td id="T_04faa_row4_col2" class="data row4 col2" >6,715.0 EGP</td>\n </tr>\n <tr>\n <td id="T_04faa_row5_col0" class="data row5 col0" >Grand Total</td>\n <td id="T_04faa_row5_col1" class="data row5 col1" >593.0 Units</td>\n <td id="T_04faa_row5_col2" class="data row5 col2" >45,324.0 EGP</td>\n </tr>\n </tbody></table>'
Yet I still can't figure out how to host this "Styler Object" in a subplot figure to export as a A4 report.
EDIT 2:
Jupyter renders the styled DF as follows:
Yet HTML Render with df.render() displays the df as follows:
Which is obviously incorrect formatting thus refraining me from continuing to research embedding the output HTML to render the report.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论