微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Python Pandas可防止单元格中的换行符

使用以下函数,我已经设法防止在笔记本中的输出中截断:

pd.set_option('display.max_colwidth', 200)
pd.set_option('display.max_columns', 0)

但是,它仍会在某些单元格中打破长行(不是截断!).我怎么能阻止它呢?

(我不关心总表的宽度,因为我只需滚动笔记本单元格的输出……)

解决方法:

对我来说,按照@EdChum的建议工作了pandas.set_option(‘display.expand_frame_repr’,False).

import pandas
matrix = [[None]*5]*4
matrix[1][1] = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut"
matrix[1][4] = matrix[1][1]
print pandas.DataFrame(matrix) # will print the matrix,
# column 4 is completely underneath the other 3 columns with all rows


pandas.set_option('display.expand_frame_repr', False)
print pandas.DataFrame(matrix) # prints only one table (no break of columns)

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐