@@ -640,19 +640,25 @@ def from_dict(cls, data, orient='columns', dtype=None):
640
640
641
641
return cls (data , index = index , columns = columns , dtype = dtype )
642
642
643
- def to_dict ( self , outtype = 'dict' ):
644
- """
645
- Convert DataFrame to dictionary.
643
+ @ deprecate_kwarg ( old_arg_name = 'outtype' , new_arg_name = 'orient' )
644
+ def to_dict ( self , orient = 'dict' ):
645
+ """ Convert DataFrame to dictionary.
646
646
647
647
Parameters
648
648
----------
649
- outtype : str {'dict', 'list', 'series', 'records'}
650
- Determines the type of the values of the dictionary. The
651
- default `dict` is a nested dictionary {column -> {index -> value}}.
652
- `list` returns {column -> list(values)}. `series` returns
653
- {column -> Series(values)}. `records` returns [{columns -> value}].
654
- Abbreviations are allowed.
649
+ orient : str {'dict', 'list', 'series', 'split', 'records'}
650
+ Determines the type of the values of the dictionary.
651
+
652
+ - dict (default) : dict like {column -> {index -> value}}
653
+ - list : dict like {column -> [values]}
654
+ - series : dict like {column -> Series(values)}
655
+ - split : dict like
656
+ {index -> [index], columns -> [columns], data -> [values]}
657
+ - records : list like
658
+ [{column -> value}, ... , {column -> value}]
655
659
660
+ Abbreviations are allowed. `s` indicates `series` and `sp`
661
+ indicates `split`.
656
662
657
663
Returns
658
664
-------
@@ -661,13 +667,17 @@ def to_dict(self, outtype='dict'):
661
667
if not self .columns .is_unique :
662
668
warnings .warn ("DataFrame columns are not unique, some "
663
669
"columns will be omitted." , UserWarning )
664
- if outtype .lower ().startswith ('d' ):
670
+ if orient .lower ().startswith ('d' ):
665
671
return dict ((k , v .to_dict ()) for k , v in compat .iteritems (self ))
666
- elif outtype .lower ().startswith ('l' ):
672
+ elif orient .lower ().startswith ('l' ):
667
673
return dict ((k , v .tolist ()) for k , v in compat .iteritems (self ))
668
- elif outtype .lower ().startswith ('s' ):
674
+ elif orient .lower ().startswith ('sp' ):
675
+ return {'index' : self .index .tolist (),
676
+ 'columns' : self .columns .tolist (),
677
+ 'data' : self .values .tolist ()}
678
+ elif orient .lower ().startswith ('s' ):
669
679
return dict ((k , v ) for k , v in compat .iteritems (self ))
670
- elif outtype .lower ().startswith ('r' ):
680
+ elif orient .lower ().startswith ('r' ):
671
681
return [dict ((k , v ) for k , v in zip (self .columns , row ))
672
682
for row in self .values ]
673
683
else : # pragma: no cover
0 commit comments