-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature Request: Provide dict object for pd.Series.to_dict() #16122
Comments
The implementation of def to_dict(self):
"""
Convert Series to {label -> value} dict
Returns
-------
value_dict : dict
"""
return dict(compat.iteritems(self)) So, if you wanted to take an argument ( |
Thanks! This will come in handy b/c a lot of my scripts I convert between dicts and series. I'm not sure what keyword to use but I think |
|
Oh yea that's true, |
I can take a crack at this one if we do want to implement it. Quick questions:
I'll use @jolespin - You probably already know this but here is an easy way to do what you want: import pandas as pd
from collections import OrderedDict
series = pd.Series({'a': 1, 'b': 2})
OrderedDict(series) |
If we wanted to do checking, then we could check It would be nice to do this for DataFrame as well. |
* ENH: Provide dict object for to_dict() #16122 * ENH: Provide dict object for to_dict() #16122 * ENH: Provide dict object for to_dict() #16122 * ENH: Provide dict object for to_dict() #16122 * ENH: Provide dict object for to_dict() #16122 * ENH: Provide dict object for to_dict() #16122 * ENH: Provide dict object for to_dict() #16122
* upstream/master: (48 commits) BUG: Categorical comparison with unordered (pandas-dev#16339) ENH: Adding 'protocol' parameter to 'to_pickle'. PERF: improve MultiIndex get_loc performance (pandas-dev#16346) TST: remove pandas-datareader xfail as 0.4.0 works (pandas-dev#16374) TST: followup to pandas-dev#16364, catch errstate warnings (pandas-dev#16373) DOC: new oauth token TST: Add test for clip-na (pandas-dev#16369) ENH: Draft metadata specification doc for Apache Parquet (pandas-dev#16315) MAINT: Add .iml to .gitignore (pandas-dev#16368) BUG/API: Categorical constructor scalar categories (pandas-dev#16340) ENH: Provide dict object for to_dict() pandas-dev#16122 (pandas-dev#16220) PERF: improved clip performance (pandas-dev#16364) DOC: try new token for docs DOC: try with new secure token DOC: add developer section to the docs DEPS: Drop Python 3.4 support (pandas-dev#16303) DOC: remove credential helper DOC: force fetch on build docs DOC: redo dev docs access token DOC: add dataframe construction in merge_asof example (pandas-dev#16348) ...
…6220) * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122
…6220) * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122 * ENH: Provide dict object for to_dict() pandas-dev#16122
I frequently use the
.to_dict()
method and was wondering how difficult it would be to implement adict_obj
argument to specify what type of dictionary will be used. For example, if one was interested in preserving the order:The text was updated successfully, but these errors were encountered: