Re: [pydata] Pandas: how to use it for time averages/cumulation of 2D numpy arrays?

41 views
Skip to first unread message

Wes McKinney

unread,
Apr 15, 2013, 12:19:39 PM4/15/13
to pyd...@googlegroups.com
On Sun, Apr 14, 2013 at 2:52 PM, Holyx Jurgen <h0lef...@gmail.com> wrote:
> Hi there,
>
> I have some climate data which can be instantaneous or aggregated (averages
> or cumulations). The time resolution of values is variable, i.e. can be
> hourly, 3hourly, 6hourly etc.
>
> I read them as a dictionary of 2D numpy arrays:
>
> vals[0]=[[...][...]]
> vals[6]=[[...][...]]
> ...
> ...
> vals[240]=[[...][...]]
> ...
>
> I need to obtain averages for a specified time frame and aggregation step in
> hours (e.g. 24 hourly averages for the period 24-96).
>
> It seems Pandas is likely to solve this (even if I have the impression to
> use a bazooka to kill ants).
> Could you tell me which are the classes that do the job? something in the
> cookbook? I've read docs and examples and I probably missed something.
>
> Thanks in advance
>
> --
> You received this message because you are subscribed to the Google Groups
> "PyData" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to pydata+un...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

You may be able to use the .resample method to do this (first convert
your data to a Panel or collection of DataFrames), but you may need to
create some "fake" timestamps in order to do so (it expects to have an
index of timestamps or periods).

I might also suggest using the raw numpy.add.reduceat aggregation
function-- we've been meaning to add something lower-level like that
to pandas but have not yet.

- Wes
Reply all
Reply to author
Forward
0 new messages