Is it possible to set column widths of a variable in pandas?

I have several columns with long lines of text in a pandas data frame, but I'm only interested in exploring one of them. Is there a way to use something along the rows pd.set_option('max_colwidth', 60), but only for a single column , and not to expand the width of all columns in my df?

+2
source share
2 answers

If you want to change the display in the Jupyter Notebook, you can use the Style function . To use this formatting only for some columns, just specify the columns (columns) to enlarge using the parameter subset. This is mainly HTML and CSS.

### Test data
df = DataFrame({'text': ['foo foo foo foo foo foo foo foo', 'bar bar bar bar bar'],
                 'number': [1, 2]})

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

enter image description here

+6

Source: https://habr.com/ru/post/1016136/


All Articles