@@ -356,21 +356,21 @@ def _tidy_repr(self, max_vals=20):
356
356
result = '%s\n %sLength: %d' % (result , namestr , len (self ))
357
357
return result
358
358
359
- def to_string (self , buf = None , na_rep = 'NaN' , nanRep = None ):
359
+ def to_string (self , buf = None , na_rep = 'NaN' , float_format = None , nanRep = None ):
360
360
if nanRep is not None : # pragma: no cover
361
361
import warnings
362
362
warnings .warn ("nanRep is deprecated, use na_rep" ,
363
363
FutureWarning )
364
364
na_rep = nanRep
365
365
366
- the_repr = self ._get_repr (na_rep = na_rep )
366
+ the_repr = self ._get_repr (float_format = float_format , na_rep = na_rep )
367
367
if buf is None :
368
368
return the_repr
369
369
else :
370
370
print >> buf , the_repr
371
371
372
372
def _get_repr (self , name = False , print_header = False , length = True ,
373
- na_rep = 'NaN' ):
373
+ na_rep = 'NaN' , float_format = None ):
374
374
vals = self .values
375
375
index = self .index
376
376
@@ -387,9 +387,14 @@ def _get_repr(self, name=False, print_header=False, length=True,
387
387
maxlen = max (len (x ) for x in string_index )
388
388
padSpace = min (maxlen , 60 )
389
389
390
+ if float_format is None :
391
+ float_format = str
392
+
390
393
def _format (k , v ):
391
394
if isnull (v ):
392
395
v = na_rep
396
+ if isinstance (v , (float , np .floating )):
397
+ v = float_format (v )
393
398
return '%s %s' % (str (k ).ljust (padSpace ), v )
394
399
395
400
it = [_format (idx , v ) for idx , v in izip (string_index , vals )]
0 commit comments