Dhruv
Dhruv

Reputation: 445

Dataframe column not showing in one line

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?

enter image description here

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.

enter image description here

Upvotes: 1

Views: 1331

Answers (2)

Dhruv
Dhruv

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

Kastakin
Kastakin

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

Related Questions