2015-10-02 21 views
7

Tôi đang cố gắng in một khung dữ liệu gấu trúc. Một trong các cột quá rộng (đó là một chuỗi rất dài). Để in, tôi đang sử dụng thư viện tabulate. Nhưng khi nó được in nó cho thấy toàn bộ nội dung của tất cả các cột trong một dòng rất dài. Dưới đây là những gì tôi thấy:Python: giới hạn chiều rộng của các cột được in của gấu trúc DataFrame

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 

vì bạn có thể thấy dòng quá dài. Làm cách nào để giới hạn số ký tự trong chuỗi được in? Ví dụ: tôi muốn dòng 3 được in dưới dạng như sau:

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

Tôi muốn giới hạn này được áp dụng cho tất cả các dòng trong bảng.

Trả lời

7

max_colwidth và (terminal) 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... 

... 

Xem options docs.

+0

Cảm ơn Andy, tôi cố gắng sử dụng các tùy chọn này với 'tabulate', và họ đã không làm việc. Nếu tôi muốn xem tất cả các cột trong một dòng nhưng các dòng được cắt nhỏ bằng cách chỉ cần gõ df (không sử dụng bảng) thì tôi cần phải làm một cái gì đó như: pd.options.display.width = 200 pd.options.display.max_colwidth = 50 – TJ1

+0

tối đa chiều rộng rất lớn, nếu tôi hiểu bạn, hãy nói 500. Điều đó sẽ đặt tất cả trên cùng một dòng. –

0

Bạn có thể làm một cái gì đó như thế này:

df['column_name'] = df['column_name'].str[:width] 
Các vấn đề liên quan