How to print DataFrame on single line

前端 未结 1 976
梦如初夏
梦如初夏 2021-02-05 10:11

With:

import pandas as pd
df = pd.read_csv(\'pima-data.csv\')
print df.head(2)

the print is automatically formatted across multiple lines:

相关标签:
1条回答
  • 2021-02-05 11:08

    You need set:

    pd.set_option('expand_frame_repr', False)
    

    option_context context manager has been exposed through the top-level API, allowing you to execute code with given option values. Option values are restored automatically when you exit the with block:

    #temporaly set expand_frame_repr
    with pd.option_context('expand_frame_repr', False):
        print (df)
    

    Pandas documentation.

    0 讨论(0)
提交回复
热议问题