如何打印Polars DataFrame时不显示开头的shape信息?
如何隐藏Polars DataFrame打印时的shape信息?
有几种简单方法可以去掉打印Polars DataFrame时开头的shape: (n, m)字符串:
1. 单次打印时指定参数
直接调用to_string()方法并传入show_shape=False,终端和Jupyter Notebook都适用:
import polars as pl df = pl.DataFrame() # 打印完整DataFrame时不显示shape print(df.to_string(show_shape=False)) # 对切片后的结果同样有效 print(df[0, :].to_string(show_shape=False))
2. 设置全局默认隐藏shape
如果希望整个会话里所有DataFrame的打印/显示都自动隐藏shape,可修改Polars的全局配置:
import polars as pl # 全局开启隐藏shape的设置 pl.Config.set_show_shape(False) df = pl.DataFrame() df # Jupyter中直接显示不会出现shape信息 print(df) # 终端打印也不会出现shape信息
后续若要恢复默认显示shape,执行pl.Config.set_show_shape(True)即可。
内容的提问来源于stack exchange,提问作者Buckley
相关产品推荐
相关产品推荐

