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).
Ta.
Use hide_index() By using hide_index() method, you can hide the Index of the DataFrame.
The most straightforward way to drop a Pandas dataframe index is to use the Pandas . reset_index() method. By default, the method will only reset the index, forcing values from 0 - len(df)-1 as the index. The method will also simply insert the dataframe index into a column in the dataframe.
The explanation: Dataframes always have an index, and there is no way of how to remove it, because it is a core part of every dataframe. ( iloc[0:4]['col name'] is a dataframe, too.) You can only hide it in your output.
Pandas DataFrame reset_index() Method The reset_index() method allows you reset the index back to the default 0, 1, 2 etc indexes. By default this method will keep the "old" idexes in a column named "index", to avoid this, use the drop parameter.
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 display(HTML(df.to_html(index=False)))
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
df.style.hide_index()
Please note that styling works only in the notebook, and not within the LaTeX conversion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With