def to_string(self):
from pandas import Series<EOL>frame = self.frame<EOL>if len(frame.columns) == <NUM_LIT:0> or len(frame.index) == <NUM_LIT:0>:<EOL><INDENT>info_line = ('<STR_LIT>'<EOL>.format(name=type(self.frame).__name__,<EOL>col=pprint_thing(frame.columns),<EOL>idx=pprint_thing(frame.index)))<EOL>text = info_line<EOL><DEDENT>else:<EOL><INDENT>strcols = self._to_str_columns()<EOL>if self.line_width is None:  <EOL><INDENT>text = self.adj.adjoin(<NUM_LIT:1>, *strcols)<EOL><DEDENT>elif (not isinstance(self.max_cols, int) or<EOL>self.max_cols > <NUM_LIT:0>):  <EOL><INDENT>text = self._join_multiline(*strcols)<EOL><DEDENT>else:  <EOL><INDENT>text = self.adj.adjoin(<NUM_LIT:1>, *strcols).split('<STR_LIT:\n>')<EOL>max_len = Series(text).str.len().max()<EOL>dif = max_len - self.w<EOL>adj_dif = dif + <NUM_LIT:1><EOL>col_lens = Series([Series(ele).apply(len).max()<EOL>for ele in strcols])<EOL>n_cols = len(col_lens)<EOL>counter = <NUM_LIT:0><EOL>while adj_dif > <NUM_LIT:0> and n_cols > <NUM_LIT:1>:<EOL><INDENT>counter += <NUM_LIT:1><EOL>mid = int(round(n_cols / <NUM_LIT>))<EOL>mid_ix = col_lens.index[mid]<EOL>col_len = col_lens[mid_ix]<EOL>adj_dif -= (col_len + <NUM_LIT:1>)<EOL>col_lens = col_lens.drop(mid_ix)<EOL>n_cols = len(col_lens)<EOL><DEDENT>max_cols_adj = n_cols - self.index<EOL>max_cols_adj = max(max_cols_adj, <NUM_LIT:2>)<EOL>self.max_cols_adj = max_cols_adj<EOL>self._chk_truncate()<EOL>strcols = self._to_str_columns()<EOL>text = self.adj.adjoin(<NUM_LIT:1>, *strcols)<EOL><DEDENT><DEDENT>self.buf.writelines(text)<EOL>if self.should_show_dimensions:<EOL><INDENT>self.buf.write("<STR_LIT>"<EOL>.format(nrows=len(frame), ncols=len(frame.columns)))<EOL><DEDENT>
Render a DataFrame to a console-friendly tabular output.