Feature Request: Provide dict object for pd.Series.to_dict()
See original GitHub issueI frequently use the .to_dict()
method and was wondering how difficult it would be to implement a dict_obj
argument to specify what type of dictionary will be used. For example, if one was interested in preserving the order:
from collections import OrderedDict
pd.Series(list("abcd")).to_dict(dict_obj=OrderedDict)
Issue Analytics
- State:
- Created 6 years ago
- Comments:6 (4 by maintainers)
Top Results From Across the Web
pandas.Series.to_dict — pandas 1.5.2 documentation
Mapping subclass to use as the return object. Can be the actual class or an empty instance of the mapping type you want....
Read more >Python | Pandas Series.to_dict() - GeeksforGeeks
Pandas Series.to_dict() function is used to convert the given Series object to {label -> value} dict or dict-like object.
Read more >python - AttributeError: 'dict' object has no attribute 'predictors'
The dict.items iterates over the key-value pairs of a dictionary. Therefore for key, value in dictionary.items() will loop over each pair.
Read more >Convert Pandas Series to Dict in Python - FavTutor
Series can store all types of data such as strings, integer, float, and other python objects. Each element in this data structure has...
Read more >arcgis.features module | ArcGIS API for Python
Creates a Feature object from a dictionary. Returns ... The itemID field from an upload() response, corresponding with the appendUploadId REST API argument....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I can take a crack at this one if we do want to implement it. Quick questions:
OrderedDict
and a few other easy ones fromcollections
, likedeque
? Some of the others might be a little odd, likedefaultdict
.pd.DataFrame
too?I’ll use
type
as the keyword - I couldn’t find any strong precedent in the standard library.kind
is used elsewhere in pandas, for exampleDataFrame.plot
, but that feels different.@jolespin - You probably already know this but here is an easy way to do what you want:
The implementation of
to_dict
is justSo, if you wanted to take an argument (
type
,kind
?) with a default ofdict
I think that’d be fine.