Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/353.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python熊猫防止单元格中的换行_Python_Pandas - Fatal编程技术网

Python熊猫防止单元格中的换行

Python熊猫防止单元格中的换行,python,pandas,Python,Pandas,使用以下功能,我已经设法防止笔记本中的输出被截断: pd.set_option('display.max_colwidth', 200) pd.set_option('display.max_columns', 0) 但是,它仍然会打断某些单元格中的长线(而不是截断!)。我怎样才能防止它这样做 (我不在乎总表有多宽,因为我可以简单地滚动笔记本单元的输出…为我工作的pandas.set_选项('display.expand_frame_repr',False),如@EdChum所建议 impor

使用以下功能,我已经设法防止笔记本中的输出被截断:

pd.set_option('display.max_colwidth', 200)
pd.set_option('display.max_columns', 0)
但是,它仍然会打断某些单元格中的长线(而不是截断!)。我怎样才能防止它这样做


(我不在乎总表有多宽,因为我可以简单地滚动笔记本单元的输出…

为我工作的
pandas.set_选项('display.expand_frame_repr',False)
,如@EdChum所建议

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)

这对我来说很有效,我正在使用Python2.7,并在Pycharm IDE上用3.6对其进行了测试

try:
    df = pd.read_excel(file,sheet_name="sheet", inplace=True, usecols="A,C:E")

    with pd.option_context('display.max_rows', 300, 'display.max_columns', 7, 'display.expand_frame_repr', False):
        print(df)

except:
    print ('failed')
然而,对于Jupyter笔记本电脑,我认为这是语法:

pd.options.display.max_rows

pd.set_option('display.max_colwidth', -1)

pd.DataFrame({'string_x': string_x}, index = [0])

如果您通过
-1
则没有限制您是说您仍然有一些超过200个字符的列?对不起,没有显示所有文本,但在一个单元格内分成多行=(请尝试
pd.set\u选项('display.expand\u frame\u repr',False)
@EdChum没有改变任何东西,它在使用pd.option\u context(…)的
节点中工作的单元格中仍然有换行符。谢谢你的回答。工作非常完美!