Michael WS
Michael WS

Reputation: 2617

Pandas panel data

I have a python panel that is index by integer values. in dict form it would look like this:

{1:{1:series,2: series,3:series,4:series} 2:{1:series,2:series,3:series,4:series}...}

I would like to roll through my data by date and on each date take a time slice in the past apply a function to every time series so I get a result such as this where X is the output of the function of timeslice.

  1 2 3 4 ...
1 X X X X
2 X X X X
3 X X X X
4 X X X X

I thought pandas.Panel.apply(func) would do this but it does not. I only get a result in 1 seemingly random column. I can iterate with for loops but i was hoping there was a faster and easier way of doing this.

I have a panel that looks like this:

 <class 'pandas.core.panel.Panel'>
 Dimensions: 1000 (items) x 3714 (major) x 1000 (minor)
 Items: 1 to 1000
 Major axis: 1997-09-10 00:00:00 to 2012-06-19 00:00:00  
 Minor axis: 1 to 1000

Upvotes: 1

Views: 3312

Answers (2)

Wes McKinney
Wes McKinney

Reputation: 105531

Have you put the data in a Panel? If you do then data.apply(f, axis=time_ax) (where time_ax is the time axis) should do the trick. Otherwise please post more context / data / examples of what's not working.

Upvotes: 2

Neodawn
Neodawn

Reputation: 1096

I think you can use a Python lamba function, to achieve that, as evidenced in the following link: http://pandas.sourceforge.net/dataframe.html#function-application

Upvotes: 0

Related Questions