@@ -758,7 +758,7 @@ def toDataMatrix(self):
758
758
from pandas .core .matrix import DataMatrix
759
759
return DataMatrix (self ._series , index = self .index )
760
760
761
- def toString (self , buffer = sys .stdout , columns = None , colSpace = 15 ,
761
+ def toString (self , buffer = sys .stdout , columns = None , colSpace = None ,
762
762
nanRep = 'NaN' , formatters = None , float_format = None ):
763
763
"""Output a tab-separated version of this DataFrame"""
764
764
series = self ._series
@@ -770,6 +770,18 @@ def toString(self, buffer=sys.stdout, columns=None, colSpace=15,
770
770
formatters = formatters or {}
771
771
ident = lambda x : x
772
772
773
+ if colSpace is None :
774
+ colSpace = {}
775
+
776
+ for c in columns :
777
+ if np .issctype (self [c ].dtype ):
778
+ colSpace [c ] = max (len (str (c )) + 4 , 12 )
779
+ else :
780
+ # hack
781
+ colSpace [c ] = 15
782
+ else :
783
+ colSpace = dict ((k , 15 ) for k in columns )
784
+
773
785
if len (columns ) == 0 or len (self .index ) == 0 :
774
786
print >> buffer , 'Empty DataFrame'
775
787
print >> buffer , repr (self .index )
@@ -778,16 +790,17 @@ def toString(self, buffer=sys.stdout, columns=None, colSpace=15,
778
790
head = _pfixed ('' , idxSpace )
779
791
780
792
for h in columns :
781
- head += _pfixed (h , colSpace )
793
+ head += _pfixed (h , colSpace [ h ] )
782
794
783
795
print >> buffer , head
784
796
785
797
for idx in self .index :
786
- ot = _pfixed (idx , idxSpace )
798
+
799
+ ot = _pfixed (idx , idxSpace - 1 )
787
800
for k in columns :
788
801
formatter = formatters .get (k , ident )
789
802
ot += _pfixed (formatter (series [k ][idx ]),
790
- colSpace , nanRep = nanRep ,
803
+ colSpace [ k ] , nanRep = nanRep ,
791
804
float_format = float_format )
792
805
print >> buffer , ot
793
806
0 commit comments