@@ -369,6 +369,9 @@ def _constructor_expanddim(self):
369
369
from pandas .core .panel import Panel
370
370
return Panel
371
371
372
+ # ----------------------------------------------------------------------
373
+ # Constructors
374
+
372
375
def __init__ (self , data = None , index = None , columns = None , dtype = None ,
373
376
copy = False ):
374
377
if data is None :
@@ -575,6 +578,8 @@ def _get_axes(N, K, index=index, columns=columns):
575
578
576
579
return create_block_manager_from_blocks ([values ], [columns , index ])
577
580
581
+ # ----------------------------------------------------------------------
582
+
578
583
@property
579
584
def axes (self ):
580
585
"""
@@ -643,6 +648,9 @@ def _is_homogeneous_type(self):
643
648
else :
644
649
return not self ._data .is_mixed_type
645
650
651
+ # ----------------------------------------------------------------------
652
+ # Rendering Methods
653
+
646
654
def _repr_fits_vertical_ (self ):
647
655
"""
648
656
Check length against max_rows.
@@ -770,6 +778,57 @@ def _repr_html_(self):
770
778
else :
771
779
return None
772
780
781
+ @Substitution (header = 'Write out the column names. If a list of strings '
782
+ 'is given, it is assumed to be aliases for the '
783
+ 'column names' )
784
+ @Substitution (shared_params = fmt .common_docstring ,
785
+ returns = fmt .return_docstring )
786
+ def to_string (self , buf = None , columns = None , col_space = None , header = True ,
787
+ index = True , na_rep = 'NaN' , formatters = None , float_format = None ,
788
+ sparsify = None , index_names = True , justify = None ,
789
+ max_rows = None , max_cols = None , show_dimensions = False ,
790
+ decimal = '.' , line_width = None ):
791
+ """
792
+ Render a DataFrame to a console-friendly tabular output.
793
+ %(shared_params)s
794
+ line_width : int, optional
795
+ Width to wrap a line in characters.
796
+ %(returns)s
797
+ See Also
798
+ --------
799
+ to_html : Convert DataFrame to HTML.
800
+
801
+ Examples
802
+ --------
803
+ >>> d = {'col1': [1, 2, 3], 'col2': [4, 5, 6]}
804
+ >>> df = pd.DataFrame(d)
805
+ >>> print(df.to_string())
806
+ col1 col2
807
+ 0 1 4
808
+ 1 2 5
809
+ 2 3 6
810
+ """
811
+
812
+ formatter = fmt .DataFrameFormatter (self , buf = buf , columns = columns ,
813
+ col_space = col_space , na_rep = na_rep ,
814
+ formatters = formatters ,
815
+ float_format = float_format ,
816
+ sparsify = sparsify , justify = justify ,
817
+ index_names = index_names ,
818
+ header = header , index = index ,
819
+ max_rows = max_rows ,
820
+ max_cols = max_cols ,
821
+ show_dimensions = show_dimensions ,
822
+ decimal = decimal ,
823
+ line_width = line_width )
824
+ formatter .to_string ()
825
+
826
+ if buf is None :
827
+ result = formatter .buf .getvalue ()
828
+ return result
829
+
830
+ # ----------------------------------------------------------------------
831
+
773
832
@property
774
833
def style (self ):
775
834
"""
@@ -2051,55 +2110,6 @@ def to_parquet(self, fname, engine='auto', compression='snappy',
2051
2110
compression = compression , index = index ,
2052
2111
partition_cols = partition_cols , ** kwargs )
2053
2112
2054
- @Substitution (header = 'Write out the column names. If a list of strings '
2055
- 'is given, it is assumed to be aliases for the '
2056
- 'column names' )
2057
- @Substitution (shared_params = fmt .common_docstring ,
2058
- returns = fmt .return_docstring )
2059
- def to_string (self , buf = None , columns = None , col_space = None , header = True ,
2060
- index = True , na_rep = 'NaN' , formatters = None , float_format = None ,
2061
- sparsify = None , index_names = True , justify = None ,
2062
- max_rows = None , max_cols = None , show_dimensions = False ,
2063
- decimal = '.' , line_width = None ):
2064
- """
2065
- Render a DataFrame to a console-friendly tabular output.
2066
- %(shared_params)s
2067
- line_width : int, optional
2068
- Width to wrap a line in characters.
2069
- %(returns)s
2070
- See Also
2071
- --------
2072
- to_html : Convert DataFrame to HTML.
2073
-
2074
- Examples
2075
- --------
2076
- >>> d = {'col1': [1, 2, 3], 'col2': [4, 5, 6]}
2077
- >>> df = pd.DataFrame(d)
2078
- >>> print(df.to_string())
2079
- col1 col2
2080
- 0 1 4
2081
- 1 2 5
2082
- 2 3 6
2083
- """
2084
-
2085
- formatter = fmt .DataFrameFormatter (self , buf = buf , columns = columns ,
2086
- col_space = col_space , na_rep = na_rep ,
2087
- formatters = formatters ,
2088
- float_format = float_format ,
2089
- sparsify = sparsify , justify = justify ,
2090
- index_names = index_names ,
2091
- header = header , index = index ,
2092
- max_rows = max_rows ,
2093
- max_cols = max_cols ,
2094
- show_dimensions = show_dimensions ,
2095
- decimal = decimal ,
2096
- line_width = line_width )
2097
- formatter .to_string ()
2098
-
2099
- if buf is None :
2100
- result = formatter .buf .getvalue ()
2101
- return result
2102
-
2103
2113
@Substitution (header = 'Whether to print column labels, default True' )
2104
2114
@Substitution (shared_params = fmt .common_docstring ,
2105
2115
returns = fmt .return_docstring )
@@ -2158,6 +2168,8 @@ def to_html(self, buf=None, columns=None, col_space=None, header=True,
2158
2168
if buf is None :
2159
2169
return formatter .buf .getvalue ()
2160
2170
2171
+ # ----------------------------------------------------------------------
2172
+
2161
2173
def info (self , verbose = None , buf = None , max_cols = None , memory_usage = None ,
2162
2174
null_counts = None ):
2163
2175
"""
0 commit comments