How can I left justify text in a pandas DataFrame column in an IPython notebook

If you’re willing to use another library, tabulate will do this –

$ pip install tabulate

and then

from tabulate import tabulate
df = pd.DataFrame ({'Text': ['abcdef', 'x'], 'Value': [12.34, 4.2]})
print(tabulate(df, showindex=False, headers=df.columns))

Text      Value
------  -------
abcdef    12.34
x          4.2

It has various other output formats also.

Leave a Comment