user997299
user997299

Reputation: 335

Pandas resample numpy array

So I have a dataframe of the form: index is a date and then I have a column that consists of np.arrays with a shape of 180x360. What I want to do is calculate the weekly mean of the data set. Example of the dataframe:

vika                                                            geop        
1990-01-01 06:00:00  [[50995.954225, 50995.954225, 50995.954225, 50...  
1990-01-02 06:00:00  [[51083.0576138, 51083.0576138, 51083.0576138,...  
1990-01-03 06:00:00  [[51045.6321168, 51045.6321168, 51045.6321168,...  
1990-01-04 06:00:00  [[50499.8436192, 50499.8436192, 50499.8436192,...  
1990-01-05 06:00:00  [[49823.5114237, 49823.5114237, 49823.5114237,...  
1990-01-06 06:00:00  [[50050.5148846, 50050.5148846, 50050.5148846,...  
1990-01-07 06:00:00  [[50954.5188533, 50954.5188533, 50954.5188533,...  
1990-01-08 06:00:00  [[50995.954225, 50995.954225, 50995.954225, 50...  
1990-01-09 06:00:00  [[50628.1596088, 50628.1596088, 50628.1596088,...  

What I've tried so far is the simple

df = df.resample('W-MON')

But I get this error:

pandas.core.groupby.DataError: No numeric types to aggregate

I've tried to change the datatype of the column to list, but it still does not work. Any idea of how to do it with resample, or any other method?

Upvotes: 1

Views: 1221

Answers (1)

HYRY
HYRY

Reputation: 97261

You can use Panel to represent 3d data:

import pandas as pd
import numpy as np

index = pd.date_range("2012/01/01", "2012/02/01")   
p = pd.Panel(np.random.rand(len(index), 3, 4), items=index)
p.resample("W-MON")

Upvotes: 1

Related Questions