gpt4 book ai didi

Python:限制pandas DataFrame打印列的宽度

转载 作者:太空狗 更新时间:2023-10-29 18:27:41 36 4
gpt4 key购买 nike

我正在尝试打印 pandas DataFrame。其中一列太宽(它是一个很长的字符串)。要打印,我正在使用 tabulate 库。但是当它被打印时,它会在很长的一行中显示所有列的全部内容。这是我看到的:

row  name                                                                                                review                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                rating

0 Planetwise Flannel Wipes These flannel wipes are OK, but in my opinion not worth keeping. I also ordered someImse Vimse Cloth Wipes-Ocean Blue-12 countwhich are larger, had a nicer, softer texture and just seemed higher quality. I use cloth wipes for hands and faces and have been usingThirsties 6 Pack Fab Wipes, Boyfor about 8 months now and need to replace them because they are starting to get rough and have had stink issues for a while that stripping no longer handles. 3
1 Planetwise Wipe Pouch it came early and was not disappointed. i love planet wise bags and now my wipe holder. it keps my osocozy wipes moist and does not leak. highly recommend it. 5
2 Annas Dream Full Quilt with 2 Shams Very soft and comfortable and warmer than it looks...fit the full size bed perfectly...would recommend to anyone looking for this type of quilt 5
3 Stop Pacifier Sucking without tears with Thumbuddy To Love\'s Binky Fairy Puppet and Adorable Book This is a product well worth the purchase. I have not found anything else like this, and it is a positive, ingenious approach to losing the binky. What I love most about this product is how much ownership my daughter has in getting rid of the binky. She is so proud of herself, and loves her little fairy. I love the artwork, the chart in the back, and the clever approach of this tool. 5
4 Stop Pacifier Sucking without tears with Thumbuddy To Love\'s Binky Fairy Puppet and Adorable Book All of my kids have cried non-stop when I tried to ween them off their paci

如您所见,该行太长了。如何限制打印字符串中的字符数?例如,我希望第 3 行打印成这样:

3  Stop Pacifier Sucking without tears ...    This is a product well worth ...     5 

我希望将此限制应用于表格中的所有行。

最佳答案

max_colwidth 和(终端)width:

In [11]: pd.options.display.width = 50

In [12]: pd.options.display.max_colwidth = 50

In [13]: df
Out[13]:
0 \
0 0 Planetwise Flannel Wipes
1 1 Planetwise Wipe Pouch
2 2 Annas Dream Full Quilt with 2 Shams
3 3 Stop Pacifier Sucking without tears with Th...
4 4 Stop Pacifier Sucking without tears with Th...

...

参见 options docs .

关于Python:限制pandas DataFrame打印列的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32901585/

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