How can I left justify text in a pandas DataFrame column in an IPython notebook -
i trying format output in ipython notebook. tried using to_string function, , neatly lets me eliminate index column. textual data right justified.
in [10]:
import pandas pd columns = ['text', 'value'] = pd.dataframe ({'text': ['abcdef', 'x'], 'value': [12.34, 4.2]}) print (a.to_string (index=false)) text value abcdef 12.34 x 4.20
the same true when printing dataframe.
in [12]:
print (a) text value 0 abcdef 12.34 1 x 4.20
the justify argument in to_string function, surprisingly, justifies column heading.
in [13]:
import pandas pd columns = ['text', 'value'] = pd.dataframe ({'text': ['abcdef', 'x'], 'value': [12.34, 4.2]}) print (a.to_string (justify='left', index=false)) text value abcdef 12.34 x 4.20
how can control justification settings individual columns?
if you're willing use library, tabulate -
$ 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.
Comments
Post a Comment