qgrid icon indicating copy to clipboard operation
qgrid copied to clipboard

Can we remove/hide the DF Index Column?

Open JohnOmernik opened this issue 7 years ago • 11 comments

Could we remove/hide the DF Index column? Even if we just hacked our way around and used a grid_option that set the index column to be 0 width?

JohnOmernik avatar Jul 05 '17 18:07 JohnOmernik

Hmm I'm not sure if there's a good way to do that currently. I'll try and look into it when I get a chance, and maybe can add an option to allow this.

TimShawver avatar Aug 08 '17 19:08 TimShawver

Just in case this isn't clear, you can change which column is the index column to an existing column inside the DataFrame (in case your problem is that it's generating "row numbers" or other useless information for you):

df.set_index('column_name', inplace=True)

The only downside at that point is the values in that column are bold.

fterbo avatar Feb 06 '18 08:02 fterbo

Just do df.style.hide_index() should hide index

JoelVaz avatar Jul 17 '19 20:07 JoelVaz

Just do df.style.hide_index() should hide index

Doesn't work.

TraitError: The 'df' trait of a QgridWidget instance must be a DataFrame, but a value of class 'pandas.io.formats.style.Styler' (i.e. <pandas.io.formats.style.Styler object at 0x0000012C937A9390>) was specified.

maralski avatar Aug 13 '19 01:08 maralski

So this could be done now that we could just set the width of that column to be 0... however, we can only reference column names by their string, and the index doesn't have a name! Can we set column options by numeric index by chance?

JohnOmernik avatar Jun 18 '20 20:06 JohnOmernik

Well good news, I can reclaim some whitespace by setting the index to width 0, however it still doesn't collapse it completely... Also it's "name" is "index" I hope this doesn't break something if a field name is index :)

JohnOmernik avatar Jun 18 '20 21:06 JohnOmernik

Ok, this can be closed, by passing this, it completely hides the index. (I think this should be a qgrid option to always do this, but this work around is ok too:

column_definitions={ 'index': { 'maxWidth': 0, 'minWidth': 0, 'width': 0 } }

JohnOmernik avatar Jun 18 '20 21:06 JohnOmernik

Thanks @JohnOmernik provide the workaround to hide index column in qgrid output dataframe. It works nicely for me.

swchen1282 avatar Sep 14 '20 02:09 swchen1282

This worked for me. column_definitions={ 'index': { 'maxWidth': 0, 'minWidth': 0, 'width': 0 } }

KUMAS599 avatar Jul 02 '21 06:07 KUMAS599

column_definitions={ 'index': { 'maxWidth': 0, 'minWidth': 0, 'width': 0 } }

This doesn't make the column width perfectly 0. It still shows a few pixels of it, hence the contents still show partially as well.

shadiakiki1986 avatar Oct 19 '21 14:10 shadiakiki1986

I made a copy of the full dataframe within the qgrid widget, and subsetted the displayed dataframe for the columns that need to be shown. Working example at:

https://gist.github.com/shadiakiki1986/b73212b148927545947f093a972ebb0c

shadiakiki1986 avatar Oct 19 '21 15:10 shadiakiki1986