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

后端 未结 4 1507
太阳男子
太阳男子 2020-12-16 14:21

I am trying to format the output in an IPython notebook. I tried using the to_string function, and this neatly lets me eliminate the index column. But the textual data is ri

4条回答
  •  清酒与你
    2020-12-16 14:48

    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.

提交回复
热议问题