Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6065227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:22:01+00:00 2026-05-23T09:22:01+00:00

I find Hadley’s plyr package for R extremely helpful, its a great DSL for

  • 0

I find Hadley’s plyr package for R extremely helpful, its a great DSL for transforming data. The problem that is solves is so common, that I face it other use cases, when not manipulating data in R, but in other programming languages.

Does anyone know if there exists an a module that does a similar thing for python? Something like:

def ddply(rows, *cols, op=lambda group_rows: group_rows):
    """group rows by cols, then apply the function op to each group
       and return the results aggregating all groups
       rows is a dict or list of values read by csv.reader or csv.DictReader"""
    pass

It shouldn’t be too difficult to implement, but would be great if it already existed. I’d implement it, I’d use itertools.groupby to group by cols, then apply the op function, then use itertools.chain to chain it all up. Is there a better solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:22:02+00:00Added an answer on May 23, 2026 at 9:22 am

    This is the implementation I drafted up:

    def ddply(rows, cols, op=lambda group_rows: group_rows): 
        """group rows by cols, then apply the function op to each group 
        rows is list of values or dict with col names (like read from 
        csv.reader or   csv.DictReader)"""
        def group_key(row):                         
            return (row[col] for col in cols)
        rows = sorted(rows, key=group_key)
        return itertools.chain.from_iterable(
            op(group_rows) for k,group_rows in itertools.groupby(rows, key=group_key)) 
    

    Another step would be to have a set of predefined functions that could be applied as op, like sum and other utility functions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hadley turned me on to the plyr package and I find myself using it
i find a lot of questions about this problem but i did not solve...
I find that, Windows 8 will be highly HTML5 + Javascript based Metro Application
I find that I'm repeating myself alot and that is of course no good.
Problem: Find people whose birthdays are tomorrow (table a), who havent got a record
I find that getting Unicode support in my cross-platform apps a real pain in
I find that the .NET event model is such that I'll often be raising
find ten integers>0 that sum to 2011 but their reciprocals sum to 1 e.g.
find() here is a function of the simple_html_dom library, that should return dom node
In following Hadley Wickham's Practical tools for exploring data and models examples in section

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.