Reputation: 445
I have a dataframe imported from csv file and I have set option of ('display.max_colwidth', None) still the column (column named 'Week') values (which are strings) come in two lines. What should I write so that it comes in one line?
One thing is that if I display less columns then it comes one line (in the above pic I had set the option to display all columns, although they are not visible in the truncated screenshot). This can be seen in below pic.
Upvotes: 1
Views: 1331
Reputation: 445
What worked for me was this answer. It modifies the CSS of the style option of dataframe.
I'm putting the code for a quick reference here or if the link gets corrupted in future.
# @RomuloPBenedetti's answer, check out the link
df.style.set_table_styles([{'selector': 'td', 'props': 'white-space: nowrap !important;'}])
Upvotes: 0
Reputation: 129
pd.set_option
sets one single option at the time. If you want to set multiple options you have to call it multiple times.
In your case that would be:
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.max_colwidth', None)
Alternatively you can set all these options using a for loop:
options = {'display.max_rows': None,
'display.max_columns': None,
'display.max_colwidth', None}
for option, value in options.items():
pd.set_option(option, value)
Upvotes: 1