如何在不包括前导的 ‘shape’ 信息的情况下打印 Polars 数据框。

huangapple go评论108阅读模式
英文:

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 笔记本中),会出现一个带有结果数据框形状的字符串。我正在寻找不打印此作为结果的方法。

简单示例如下:

  1. >>> import polars as pl
  2. >>> df = pl.DataFrame()
  3. >>> df
  4. shape: (0, 0)
  5. ┌┐
  6. ╞╡
  7. └┘
  8. >>> print(df)
  9. shape: (0, 0)
  10. ┌┐
  11. ╞╡
  12. └┘
  13. >>> print(df[0, :])
  14. shape: (0, 0)
  15. ┌┐
  16. ╞╡
  17. └┘

我的问题是如何仅打印数据框,而不带着那个隐藏的 "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:

  1. >>> import polars as pl
  2. >>> df = pl.DataFrame()
  3. >>> df
  4. shape: (0, 0)
  5. ┌┐
  6. ╞╡
  7. └┘
  8. >>> print(df)
  9. shape: (0, 0)
  10. ┌┐
  11. ╞╡
  12. └┘
  13. >>> print(df[0, :])
  14. shape: (0, 0)
  15. ┌┐
  16. ╞╡
  17. └┘

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

  1. import polars as pl
  2. pl.Config.set_tbl_hide_dataframe_shape(True)
  3. df = pl.DataFrame({'col1': range(3), 'col2': ['a', 'b', 'c']})
  4. print(df)

results in

  1. ┌──────┬──────┐
  2. col1 col2
  3. --- ---
  4. i64 str
  5. ╞══════╪══════╡
  6. 0 a
  7. 1 b
  8. 2 c
  9. └──────┴──────┘
英文:

I found a native way: you could use pl.Config.set_tbl_hide_dataframe_shape. This

  1. import polars as pl
  2. pl.Config.set_tbl_hide_dataframe_shape(True)
  3. df = pl.DataFrame({'col1': range(3), 'col2': ['a', 'b', 'c']})
  4. print(df)

results in

  1. ┌──────┬──────┐
  2. col1 col2
  3. --- ---
  4. i64 str
  5. ╞══════╪══════╡
  6. 0 a
  7. 1 b
  8. 2 c
  9. └──────┴──────┘

huangapple
  • 本文由 发表于 2023年3月15日 21:33:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/75745438.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定