Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change the cell width of a data frame in Jupyter Notebook

I have a data frame with one column which contains long text descriptions.

I would like to display all the text without truncating it, but in a manner in which the column makes wider instead of making the row higher.


If I let pandas' default settings, I get next:

enter image description here


But if I try to remove truncate using pd.set_option('display.max_colwidth', -1), the row gets higher while row width mantains almost equal:

enter image description here

like image 375
Haritz Laboa Avatar asked May 18 '19 10:05

Haritz Laboa


People also ask

How can you increase the width of a cell *?

Resize columns Select a column or a range of columns. On the Home tab, select Format > Column Width (or Column Height). Type the column width and select OK.

How do you shrink a cell in Jupyter Notebook?

Highlight a cell and then click on the blue bar next to it. You'll see it represented as three dots now. It will be respected when you save and reopen later or elsewhere. There is further features and options, such as View > Collapse All Code , see here and the link here.

How do I format a cell in Jupyter Notebook?

a keyboard shortcut for reformatting the current code-cell (default shortcut is Ctrl-L , can also be configured not to add the keyboard shortcut). a keyboard shortcut for reformatting the whole notebook (default shortcut is Ctrl-Shift-L , can also be configured not to add the keyboard shortcut).


1 Answers

Use the below setting to change only for 1 column.

df.style.set_properties(subset=['ad_description'], **{'width-min': '300px'})

Edits: @Haritz Laboa: Thanks for confirming that 'width-min' works and not 'width'.

like image 102
vb_rises Avatar answered Oct 17 '22 01:10

vb_rises