1

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?

1
  • 1
    Storing numpy arrays inside a DataFrame is not a good idea usually. You'll be quite limited in what you can do (as you're finding out). Your data is probably well suited for an xarray.Dataset which builds on top of numpy and pandas: xarray.pydata.org/en/stable/data-structures.html, resample Commented Jan 21, 2016 at 22:29

1 Answer 1

1

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")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.