Polars / Python 限制打印表格输出行数

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

Polars / Python Limits Number of Printed Table Output Rows

问题

I understand your request. Here's the translated content:

有人知道为什么 Polars(或者可能是我的 PyCharm 设置或 Python 调试器)限制了输出中的行数吗?这让我很烦恼。

这是我正在运行的 Polars 代码,但我怀疑它与 Polars 无关,因为在谷歌上几乎找不到相关信息(而 ChatGPT 说它的信息太旧了哈哈)。

  1. import polars as pl
  2. df = pl.scan_parquet('/path/to/file.parquet')
  3. result_df = (
  4. df
  5. .filter(pl.col("condition_category") == 'unknown')
  6. .groupby("type")
  7. .agg(
  8. [
  9. pl.col("type").count().alias("counts"),
  10. ]
  11. )
  12. ).collect()
  13. print(result_df)

Polars / Python 限制打印表格输出行数

英文:

Does anyone know why polars (or maybe my pycharm setup or python debugger) limits the number of rows in the output? This drives me nuts.

Here is the polars code i am running but I do suspect its not polars specific as there isnt much out there on google (and chatgpt said its info is too old haha).

  1. import polars as pl
  2. df = pl.scan_parquet('/path/to/file.parquet')
  3. result_df =(
  4. df
  5. .filter(pl.col("condition_category") == 'unknown')
  6. .groupby("type")
  7. .agg(
  8. [
  9. pl.col("type").count().alias("counts"),
  10. ]
  11. )
  12. ).collect()
  13. print(result_df)

Polars / Python 限制打印表格输出行数

答案1

得分: 2

以下部分已翻译:

"Looks like the following will work. Thanks to @wayoshi for sharing this. I will say that the defaults are way too conservative!

  1. cfg.set_tbl_rows(1000)
  2. print(result_df)

or throw this at the top of your script if you prefer to not manage contexts.

  1. import polars as pl
  2. # Configure Polars
  3. cfg = pl.Config()
  4. cfg.set_tbl_rows(2000)
  5. ```"
  6. [1]: https://pola-rs.github.io/polars/py-polars/html/reference/config.html
  7. <details>
  8. <summary>英文:</summary>
  9. Looks like the following will work. Thanks to @wayoshi for sharing [this][1]. I will say that the defaults are way too conservative!

with pl.Config() as cfg:
cfg.set_tbl_rows(1000)
print(result_df)

  1. or throw this at the top of your script if you prefer to not manage contexts.

import polars as pl

Configure Polars

cfg = pl.Config()
cfg.set_tbl_rows(2000)

  1. [1]: https://pola-rs.github.io/polars/py-polars/html/reference/config.html
  2. </details>

huangapple
  • 本文由 发表于 2023年4月17日 21:46:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76035847.html
匿名

发表评论

匿名网友

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

确定