看起来它需要增强。函数中的相关代码repr
似乎在这里:
max_rows = get_option("display.max_rows")
max_cols = get_option("display.max_columns")
show_dimensions = get_option("display.show_dimensions")
if get_option("display.expand_frame_repr"):
width, _ = console.get_console_size()
else:
width = None
self.to_string(buf=buf, max_rows=max_rows, max_cols=max_cols,
line_width=width, show_dimensions=show_dimensions)
因此,要么您通过expand_frame_repr=True
并且它包裹在线宽上,要么您通过expand_frame_repr=False
并且它不应该。但看起来代码中有一个错误(这应该是pandas 0.20.3 iirc):
在pd.io.formats.format.DataFrameFormatter
:
def _chk_truncate(self):
"""
Checks whether the frame should be truncated. If so, slices
the frame up.
"""
from pandas.core.reshape.concat import concat
# Column of which first element is used to determine width of a dot col
self.tr_size_col = -1
# Cut the data to the information actually printed
max_cols = self.max_cols
max_rows = self.max_rows
if max_cols == 0 or max_rows == 0: # assume we are in the terminal
# (why else = 0)
(w, h) = get_terminal_size()
self.w = w
self.h = h
if self.max_rows == 0:
dot_row = 1
prompt_row = 1
if self.show_dimensions:
show_dimension_rows = 3
n_add_rows = (self.header + dot_row + show_dimension_rows +
prompt_row)
# rows available to fill with actual data
max_rows_adj = self.h - n_add_rows
self.max_rows_adj = max_rows_adj
# Format only rows and columns that could potentially fit the
# screen
if max_cols == 0 and len(self.frame.columns) > w:
max_cols = w
if max_rows == 0 and len(self.frame) > h:
max_rows = h
看起来它打算做你想做的事,但还没有完成。它检查max_cols
的是列数,而不是列的总宽度。
因此,您可以创建一个show_df
函数来计算正确的列数并将其显示在option_context
类似 pi2Squared 的答案中,或者在此处修复它(如果您需要分发补丁,可以提交补丁)。