使用以下功能,我已经设法防止笔记本计算机中的输出被截断:
pd.set_option('display.max_colwidth', 200)
pd.set_option('display.max_columns', 0)
Run Code Online (Sandbox Code Playgroud)
但是,它仍然会破坏某些单元格中的长行(不会截断!)。我如何防止它这样做?
(我不在乎总表有多宽,因为我可以简单地滚动笔记本单元的输出...)
Zia*_*ian 15
对我来说,pandas.set_option('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)
Run Code Online (Sandbox Code Playgroud)
小智 5
这对我有用,我使用的是 python 2.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')
Run Code Online (Sandbox Code Playgroud)
但是,对于 Jupyter Notebooks,我相信这是语法:
pd.options.display.max_rows
pd.set_option('display.max_colwidth', -1)
pd.DataFrame({'string_x': string_x}, index = [0])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4139 次 |
| 最近记录: |