如何在python中最好使用pandas添加表格标题 [英] How to add table title in python preferably with pandas

查看:54
本文介绍了如何在python中最好使用pandas添加表格标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在输出中添加一个表格标题.在 r 中这样做相对容易flextable,你只需要使用 set_caption() 函数,python 中是否有类似的包与 pandas 数据帧(也许PTable)?

I would like to add a table title in the out put. It's relatively easy to do this in r with flextable, you just have to use function set_caption(), is there a similar package in python with pandas dataframe (maybe PTable)?

这就是我现在所拥有的,

This is what I have right now,

这就是我想要的

请帮忙,谢谢各位!

推荐答案

您是否尝试过这样做?

df.style.set_caption("Hello World")

来源:熊猫造型

如果您可以使用 matplotlib

import matplotlib.pyplot as plt
import pandas as pd

my_frame = pd.DataFrame(data={'simulation1':[71,4.8,65,4.7],
                              'simulation2':[71,4.8,69,4.7],
                              'simulation3':[70,3.8,68,4.9],
                              'experiment':[70.3,3.5,65,4.4]})
#my_frame Display pandas table

fig = plt.figure(figsize = (8, 2))
ax = fig.add_subplot(111)

ax.table(cellText = my_frame.values,
          rowLabels = my_frame.index,
          colLabels = my_frame.columns,
          loc = "center"
         )
ax.set_title("Top 10 Fields of Research by Aggregated Funding Amount")

ax.axis("off");

这篇关于如何在python中最好使用pandas添加表格标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆