You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wish I could iterate through dictionaries of each row's contents in a DataFrame, the same way I could do so with namedtuples through itertuples(). Performing the namedtuple-to-dict conversion process isn't difficult normally, but in some situation (e.g. doing so in a list/set/dict comprehension), it's more convenient to have a generator that does the process automatically for you.
Feature Description
Add a new function to DataFrames, iterdicts, that takes an index argument (equivalent to the same argument in itertuples) and returns each row as a dictionary the same way itertuples does so as a namedtuple. (No need to take a "name" argument, since that's irrelevant for dictionaries.)
@Liam3851 No, I'm using dict-merging, which Series is incompatible with. Also, iterrows is much slower than itertuples, and the iterdicts function I showed above seemed almost as fast as the latter when I tried it, though I'll admit I didn't perform extensive benchmarking.
Feature Type
Adding new functionality to pandas
Changing existing functionality in pandas
Removing existing functionality in pandas
Problem Description
I wish I could iterate through dictionaries of each row's contents in a DataFrame, the same way I could do so with namedtuples through itertuples(). Performing the
namedtuple
-to-dict
conversion process isn't difficult normally, but in some situation (e.g. doing so in a list/set/dict comprehension), it's more convenient to have a generator that does the process automatically for you.Feature Description
Add a new function to DataFrames,
iterdicts
, that takes anindex
argument (equivalent to the same argument initertuples
) and returns each row as a dictionary the same way itertuples does so as a namedtuple. (No need to take a "name" argument, since that's irrelevant for dictionaries.)Alternative Solutions
Write a custom function that does the same thing externally.
Additional Context
No response
The text was updated successfully, but these errors were encountered: