from collections import UserDict class CustomDict(UserDict): pass cd = CustomDict(col_1=[1,2], col_2=[3,4]) pd.DataFrame.from_dict(cd) output: 0 0 col_1 1 col_2 Issue Description Pandas will not accept UserDict and other custom dict-like objects for DataFrame creation. Subclassing...
withcollections.UserDictandcollections.UserList by inheriting fromlist,dict, andsetdirectly While creating and solving many exercises involving custom collections, I’ve realized that inheriting fromlist,dict, andsetis often subtly painful. I’m writing this article to explain why I often don’t r...
To learn more about how to safely subclass the built-in dict type in Python, check out Custom Python Dictionaries: Inheriting From dict vs UserDict. Remove ads Removing Items From Mutable Nested CollectionsSometimes, you may need to nest mutable types, such as lists and dictionaries, in outer...
65 Exploring UserDict: A Wrapper Class ... 66 Special Class Methods ... 69 Getting and Setting Items ...