Using ipysheet, how do I adjust the column width for an index column?

Viewed 341

I am trying to work through the simple ipysheet example below and have not been able to find a way to increase the column width associated with the date index in the resulting sheet in a Jupyter Notebook

import ipysheet as ip  
import pandas as pd  

dates = pd.date_range('20130101', periods=6)  
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD'))  
sheet = ip.from_dataframe(df)  
display(sheet)  

Resulting Output

1 Answers

I'm having the same problem, and don't see anything in the code that indicates this is possible.

You can see in the ipysheet code that Sheet extends ipywidget.DOMWidget, which in turn extends ipywidget.Widget. You can probably send some custom CSS into the constructor that will help it render the way you want but that's going to take a lot of research.

The workaround is to reset the index on your DataFrame so that dates is just a column.

df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list('ABCD'))  
df = df.reset_index()
sheet = ip.from_dataframe(df) 

Not exactly what you want, but for my purposes it's definitely good enough.

Related