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

  • Home
  • SEARCH
  • 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 9193905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:16:34+00:00 2026-06-17T21:16:34+00:00

I have a dataset in Pytables, which looks something like class myData(IsDescription): date =

  • 0

I have a dataset in Pytables, which looks something like

class myData(IsDescription):
    date = StringCol(16)
    item = Int32Col()

I have multiple items per same date, for example:

'2010-01-01', 5
'2010-01-01', 6
'2010-01-02', 7
'2010-01-02', 8

Is there a way to iterate over unique dates and then over items in the date? I mean something like

for date in DATE
    print date
     for ITEM
         print item
  • 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-06-17T21:16:36+00:00Added an answer on June 17, 2026 at 9:16 pm

    I am not familiar with the inner-workings of Pytables (so this may not be in-line with what you are looking for), but the groupby function in the itertools module is very useful in these types of situations (note the sorting step below – this is important in this case in order to get groupby to group all items with the same date. See here for more info.):

    In [1]: from itertools import groupby
    
    In [2]: from operator import attrgetter
    
    In [3]: class myData(object):
        def __init__(self, date, item):
            self.date = date
            self.item = item
       ...:         
    
    In [4]: l = [myData('2012-01-01', 'thing'), myData('2012-01-01', 'another thing'), myData('2013-01-01', 'and another')]
    
    In [5]: l_sorted = sorted(l, key=attrgetter('date'))
    
    In [6]: for date, my_objects in groupby(l_sorted, key=attrgetter('date')):
       ...:     print date
       ...:     for obj in my_objects:
       ...:         print obj.item
       ...:         
    2012-01-01
    thing
    another thing
    2013-01-01
    and another
    

    The basic pattern here is to get a list/container that holds the objects you want to group. You then sort that list based by the attribute by which we will later be grouping (in this case, date). You then pass that sorted list to the groupby function, which will emit two values in each iteration – a key that represents the value by which you grouped (so here it will be the date of each group) and a group iterator that contains all of your objects that share that same date key. You can then iterate through that group, pulling out the item attribute of each object.

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

Sidebar

Related Questions

I have a dataset that looks like this: 0 _ _ 23.0186E-03 10 _
I have a dataset for which I have extracted the date at which an
I have a dataset which I'd like to consume with tbb::parallel_for in intervals of
I have a dataset that looks a bit like: <item1> <isLocated> <someAddress> <item2> <isLocated>
I have a dataset that looks like: ColA ColB ColC ColD ColE rs778 C
I have a DataSet with multiple DataTables that I'd like to bind to a
I have a dataset of 2D points (~500k of them) on which I'd like
I have a dataset that looks like: order year value 1 1990 2 1
I have DataSet which has 3 columns. Name - insurance comp. name - treatmentDate
I have a dataset with multiple tables. One table in particular has one record

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.