Pandas dataframe hide index functionality?


Is it possible to hide the index when displaying pandas DataFrames, so that only the column names appear at the top of the table?

This would need to work for both the html representation in ipython notebook and to_latex() function (which I’m using with nbconvert).

Asked By: J Grif



Set index=False

For ipython notebook:

print df.to_string(index=False)

For to_latex:

Answered By: waitingkuo

I added the following cell to my notebook which works fine in Jupyter 4.0.2.

Note: It removes the first column of ‘any’ table even when there is no index.

# Execute this cell to remove the first column of dataframe tables (to remove index column)
from IPython.core.display import HTML
    table.dataframe thead th:first-child {
        display: none;
    table.dataframe tbody th {
        display: none;
Answered By: Willem van Doesburg

As has been pointed out by @waitingkuo, index=False is what you need. If you want to keep the nice table layout within your ipython notebook, you can use:

from IPython.display import display, HTML
Answered By: Thomas

Set index=False.


DataFrame.to_csv("filename", index=False)

This will work.

Answered By: Bhaskar Mitra

Starting from v. 0.17.1 it is possible to hide the index via styling, see hiding the index or colums: if df is your Data Frame just do

Please note that styling works only in the notebook, and not within the LaTeX conversion.

Answered By: Stefano M

You just try this code, might help you.

The style.hide_index is depreciated since Pandas 1.4. For those wanting to know how to hide the index in Notebooks with latest pandas use:'index')
Answered By: mrkbutty


Else you will see:

FutureWarning: this method is deprecated in favour of `Styler.hide(axis="index")`

See DEPR REF: hide(axis=..) replaces hide_index and hide_columns #43771

Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.