gpt4 book ai didi

python - 类型错误 : 'Styler' object is not subscriptable

转载 作者:行者123 更新时间:2023-12-04 15:32:25 29 4
gpt4 key购买 nike

我可以像这样访问列的子集:

df[[5, 6]]

..但在以下行之后将文本向左推送并使其更具可读性:
df = df.style.set_properties(**{'text-align': 'left'})

..同样的命令会产生一个错误:
TypeError: 'Styler' object is not subscriptable

这是预期的行为,还是您现在需要使用一些技巧才能到达列?

正在使用 Python 3.7.6 和 Pandas 1.0.3

最佳答案

Styler 不返回数据框,而是返回样式对象。从那里,您应该/可以使用 apply函数来格式化您的数据框打印输出。例如:

 # apply style on the columns
df.style.apply(lambda x: ["text-align:right"]*len(x))

关于python - 类型错误 : 'Styler' object is not subscriptable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60952164/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com