Ben Anuworakarn
Ben Anuworakarn

Reputation: 11

How do I plot a pandas DataFrame as a table without the index column?

I'm using pandas.plotting.table to generate a matplotlib table for my data. The pandas documentation states that if the rowLabels kwarg is not specified, it uses the data index. However, I want to plot my data without the index at all. I couldn't find a way to override the setting in the pyplot table either.

Currently my output looks like this:
enter image description here

Upvotes: 0

Views: 6192

Answers (2)

Uendel Rocha
Uendel Rocha

Reputation: 301

Try this:

import pandas as pd

df = <load your data into a pandas dataframe>
df.style.hide(axis='index')

Upvotes: 0

McManip
McManip

Reputation: 300

I found it easier to bypass pandas and to fallback to calling matplotlib routines to do the plotting.

import matplotlib.pyplot as plt
import pandas as pd

df = <load your data into a pandas dataframe>

fig, ax = plt.subplots(1, 1)
ax.table(cellText=df.values, colLabels=df.keys(), loc='center')
plt.show()

See the docs for ax.table

Upvotes: 3

Related Questions