简体   繁体   English

熊猫重新采样numpy数组

[英]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. 所以我有一个形式的数据框:index是一个日期,然后有一个由np.arrays组成的列,其形状为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 pandas.core.groupby.DataError:没有要聚合的数字类型

I've tried to change the datatype of the column to list, but it still does not work. 我试图将列的数据类型更改为list,但仍然无法正常工作。 Any idea of how to do it with resample, or any other method? 关于如何使用重采样或任何其他方法进行处理的任何想法?

You can use Panel to represent 3d data: 您可以使用Panel表示3d数据:

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")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM