qgrid
qgrid copied to clipboard
Can we remove/hide the DF Index Column?
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?
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.
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.
Just do df.style.hide_index() should hide index
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.
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?
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 :)
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 } }
Thanks @JohnOmernik provide the workaround to hide index column in qgrid output dataframe. It works nicely for me.
This worked for me. column_definitions={ 'index': { 'maxWidth': 0, 'minWidth': 0, 'width': 0 } }
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.
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