英文:
How to print Polars dataframe without the leading 'shape' information
问题
I will provide the translation without the code part. Here is the translated text:
当我打印 Polars 数据框(例如,从终端或在 Jupyter 笔记本中),会出现一个带有结果数据框形状的字符串。我正在寻找不打印此作为结果的方法。
简单示例如下:
>>> import polars as pl
>>> df = pl.DataFrame()
>>> df
shape: (0, 0)
┌┐
╞╡
└┘
>>> print(df)
shape: (0, 0)
┌┐
╞╡
└┘
>>> print(df[0, :])
shape: (0, 0)
┌┐
╞╡
└┘
我的问题是如何仅打印数据框,而不带着那个隐藏的 "shape: [n, m]" 字符串?
英文:
When I print a Polars dataframe (e.g., from terminal or within Jupyter notebook), there is a leading string citing the shape of the resultant dataframe. I am looking for the method to not have this printed as part of the result.
The simple example would be the following:
>>> import polars as pl
>>> df = pl.DataFrame()
>>> df
shape: (0, 0)
┌┐
╞╡
└┘
>>> print(df)
shape: (0, 0)
┌┐
╞╡
└┘
>>> print(df[0, :])
shape: (0, 0)
┌┐
╞╡
└┘
My question is how would I print only the dataframe without the lurking "shape: [n, m]" string?
答案1
得分: 3
I found a native way: you could use pl.Config.set_tbl_hide_dataframe_shape
. This
import polars as pl
pl.Config.set_tbl_hide_dataframe_shape(True)
df = pl.DataFrame({'col1': range(3), 'col2': ['a', 'b', 'c']})
print(df)
results in
┌──────┬──────┐
│ col1 ┆ col2 │
│ --- ┆ --- │
│ i64 ┆ str │
╞══════╪══════╡
│ 0 ┆ a │
│ 1 ┆ b │
│ 2 ┆ c │
└──────┴──────┘
英文:
I found a native way: you could use pl.Config.set_tbl_hide_dataframe_shape
. This
import polars as pl
pl.Config.set_tbl_hide_dataframe_shape(True)
df = pl.DataFrame({'col1': range(3), 'col2': ['a', 'b', 'c']})
print(df)
results in
┌──────┬──────┐
│ col1 ┆ col2 │
│ --- ┆ --- │
│ i64 ┆ str │
╞══════╪══════╡
│ 0 ┆ a │
│ 1 ┆ b │
│ 2 ┆ c │
└──────┴──────┘
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论