Summarizing data by week

M.-A. Lemburg mal at egenix.com
Thu Jan 11 18:04:44 EST 2007


On 2007-01-09 20:57, Mike Orr wrote:
> What's the best way to summarize data by week?  I have a set of
> timestamped records, and I want a report with one row for each week in
> the time period, including zero rows if there are weeks with no
> activity.  I was planning to use ISO weeks because datetime has a
> convenient .isocalendar() method, but I want each output row to have a
> label like this:
> 
>     2006 week 5 (Feb)
> 
> However, to get the month (of the Thursday of that week) I have to
> convert it back to an actual date,and I don't see a method to do that
> in datetime or dateutil or mx.DateTime.

You probably want to use mx.DateTime.ISO.WeekTime():

def WeekTime(year,isoweek=1,isoday=1,hour=0,minute=0,second=0.0):

    """Week(year,isoweek=1,isoday=1,hour=0,minute=0,second=0.0)

       Returns a DateTime instance pointing to the given ISO week and
       day.  isoday defaults to 1, which corresponds to Monday in the
       ISO numbering. The time part is set as given.

    """

The ISO submodule has more APIs related to ISO weeks and the
ISO date format in general:

    http://www.egenix.com/files/python/mxDateTime.html#ISO

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Jan 12 2007)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________

::: Try mxODBC.Zope.DA for Windows,Linux,Solaris,FreeBSD for free ! ::::



More information about the Python-list mailing list