Python Pandas可防止单元格中的换行符
发布时间:2020-12-20 13:13:32 所属栏目:Python 来源:网络整理
导读:使用以下函数,我已经设法防止在笔记本中的输出中截断: pd.set_option('display.max_colwidth',200)pd.set_option('display.max_columns',0) 但是,它仍会在某些单元格中打破长行(不是截断!).我怎么能阻止它呢? (我不关心总表的宽度,因为我只需滚动笔记本单
使用以下函数,我已经设法防止在笔记本中的输出中截断:
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) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |