close

How to add table title in python preferably with pandas

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How to add table title in python preferably with pandas in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How to add table title in python preferably with pandas?

  1. How to add table title in python preferably with pandas?

    Here's an alternative way to present your table if you're okay with using matplotlib

  2. add table title in python preferably with pandas

    Here's an alternative way to present your table if you're okay with using matplotlib

Method 1

Have you tried this doing this?

df.style.set_caption("Hello World")

Source: Pandas Styling

EDIT:

Here’s an alternative way to present your table if you’re okay with using 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");

Method 2

It appears this does not set the caption ‘inplace’, like:

df.reset_index(drop=True, inplace=True)

is the same as:

df = df.reset_index(drop=True)

Instead try:

df = df.style.set_caption('Top 10 Fields of Research by Aggregated Funding Amount')

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read