且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在单行上打印DataFrame

更新时间:2023-12-04 10:52:40

您需要设置:

pd.set_option('expand_frame_repr', False)

option_context上下文管理器已通过***API公开,您可以使用给定的选项值执行代码.退出with块时,选项值将自动恢复:

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)

熊猫文档.