#NEWLINE# def to_string( self ) : #NEWLINE# #INDENT# '\n        Render a DataFrame to a console-friendly tabular output.\n        ' #NEWLINE# from pandas import Series #NEWLINE# frame = self . frame #NEWLINE# if ( ( len ( frame . columns ) == 0 ) or ( len ( frame . index ) == 0 ) ) : #NEWLINE# #INDENT# info_line = ( u ( 'Empty %s\nColumns: %s\nIndex: %s' ) % ( type ( self . frame ) . __name__ , pprint_thing ( frame . columns ) , pprint_thing ( frame . index ) ) ) #NEWLINE# text = info_line #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# strcols = self . _to_str_columns ( ) #NEWLINE# if ( self . line_width is None ) : #NEWLINE# #INDENT# text = self . adj . adjoin ( 1 , * strcols ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( ( not isinstance ( self . max_cols , int ) ) or ( self . max_cols > 0 ) ) : #NEWLINE# #INDENT# text = self . _join_multiline ( * strcols ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# text = self . adj . adjoin ( 1 , * strcols ) . split ( '\n' ) #NEWLINE# row_lens = Series ( text ) . apply ( len ) #NEWLINE# max_len_col_ix = np . argmax ( row_lens ) #NEWLINE# max_len = row_lens [ max_len_col_ix ] #NEWLINE# headers = [ ele [ 0 ] for ele in strcols ] #NEWLINE# size_tr_col = len ( headers [ self . tr_size_col ] ) #NEWLINE# max_len += size_tr_col #NEWLINE# dif = ( max_len - self . w ) #NEWLINE# adj_dif = dif #NEWLINE# col_lens = Series ( [ Series ( ele ) . apply ( len ) . max ( ) for ele in strcols ] ) #NEWLINE# n_cols = len ( col_lens ) #NEWLINE# counter = 0 #NEWLINE# while ( ( adj_dif > 0 ) and ( n_cols > 1 ) ) : #NEWLINE# #INDENT# counter += 1 #NEWLINE# mid = int ( round ( ( n_cols / 2.0 ) ) ) #NEWLINE# mid_ix = col_lens . index [ mid ] #NEWLINE# col_len = col_lens [ mid_ix ] #NEWLINE# adj_dif -= ( col_len + 1 ) #NEWLINE# col_lens = col_lens . drop ( mid_ix ) #NEWLINE# n_cols = len ( col_lens ) #NEWLINE# #UNINDENT# max_cols_adj = ( n_cols - self . index ) #NEWLINE# self . max_cols_adj = max_cols_adj #NEWLINE# self . _chk_truncate ( ) #NEWLINE# strcols = self . _to_str_columns ( ) #NEWLINE# text = self . adj . adjoin ( 1 , * strcols ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not self . index ) : #NEWLINE# #INDENT# text = text . replace ( '\n ' , '\n' ) . strip ( ) #NEWLINE# #UNINDENT# self . buf . writelines ( text ) #NEWLINE# if self . should_show_dimensions : #NEWLINE# #INDENT# self . buf . write ( ( '\n\n[%d rows x %d columns]' % ( len ( frame ) , len ( frame . columns ) ) ) )