You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Polars如何取消文本省略,完整显示Link列内容?

让Polars显示完整的Link列文本

以下是几种实用的设置方法,根据需求选择即可:

1. 全局设置(对所有DataFrame生效)

通过配置Polars的全局显示参数,将字符串的最大显示长度设为无限制(或一个足够大的数值),这样所有字符串列都会完整显示:

import polars as pl

# 设置字符串显示长度为无限制,也可指定具体数值如1000
pl.Config.set_fmt_str_lengths(None)

# 后续所有DataFrame的字符串列都会展示完整内容
df = pl.DataFrame({
    "Link": ["https://example.com/very/long/url/path/that/was/truncated", "https://another-long-url.com/path/to/resource"],
    "Name": ["name1", "name2"]
})
print(df)

2. 临时设置(仅对当前输出生效)

若不想修改全局配置,可使用上下文管理器临时调整显示参数,只影响当前的打印操作:

import polars as pl

df = pl.DataFrame({
    "Link": ["https://example.com/very/long/url/path/that/was/truncated", "https://another-long-url.com/path/to/resource"],
    "Name": ["name1", "name2"]
})

# 临时开启完整字符串显示
with pl.Config(fmt_str_lengths=1000):
    print(df)

3. 单独查看目标列

如果只需要查看Link列的完整内容,直接提取该列打印即可,单列显示默认会展示完整文本:

# 直接打印Link列
print(df["Link"])

内容的提问来源于stack exchange,提问作者Pytan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 10:13:29