Reputation: 6197
I see that text can be aligned to the left or to the right.
There are situations where one column has a lot of text and then all other columns have their values in the vertical middle of the column.
df.style.set_properties(**{'text-align': 'right'})
I tried
df.style.set_properties(**{'text-align': 'top'})
And it didn't work
It seems that this is borrowed from css so I also tried
df.style.set_properties(**{'vertical-align': 'top'})
Upvotes: 2
Views: 1599
Reputation: 4304
The CSS pairing you want is: "vertical-align": "text-top"
Example:
import pandas as pd
pd.set_option('display.max_colwidth', None)
d = {'A': [1, "This is a medium long value"], 'B': [1, "This is a medium long value"], 'C': [1, "This is a medium long value"], 'D': [1, "This is a medium long value"],
'E': [1, "This is a medium long value"], 'F': [1, "This is a medium long value"], 'G': [1, "This is a medium long value"], 'H': [1, "This is a medium long value"],
'X': [1, "This is a really really really long value that goes on and on and on and on and on and on and on and on."]}
df = pd.DataFrame(data=d)
df.style.set_properties(**{"vertical-align": "text-top"})
Without "vertical-align": "text-top"
:
With "vertical-align": "text-top"
Upvotes: 2