Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用重采样对datetime索引的数据帧进行数值积分。()_Python_Pandas_Scipy - Fatal编程技术网

Python 使用重采样对datetime索引的数据帧进行数值积分。()

Python 使用重采样对datetime索引的数据帧进行数值积分。(),python,pandas,scipy,Python,Pandas,Scipy,我想把5分钟的间歇时间整合成1小时。熊猫本身有办法做到这一点吗?类似于如何使用重采样来缩小和平均?我想缩小比例,并使用5分钟的数据返回每个1小时周期的积分 import pandas as pd np.random.seed(1234) df = pd.DataFrame(np.random.rand(300,4), columns=list('ABCD'), index=pd.date_range('2017-01-01 09:00:00', periods=300, freq='5min')

我想把5分钟的间歇时间整合成1小时。熊猫本身有办法做到这一点吗?类似于如何使用重采样来缩小和平均?我想缩小比例,并使用5分钟的数据返回每个1小时周期的积分

import pandas as pd
np.random.seed(1234)
df = pd.DataFrame(np.random.rand(300,4), columns=list('ABCD'), index=pd.date_range('2017-01-01 09:00:00', periods=300, freq='5min'))
df=df.resample('1h').mean()  #can as similar method be used to find the numerical integral (eg. with trapezoidal rule)?

可以使用scipy.integrate.simps应用辛普森规则进行集成。您必须使用自定义重采样器,并在作为参数提供给自定义重采样器的函数中应用Simpsons集成

以下是您如何做到这一点:

def custom_function(array_like):
    return  sp.integrate.simps(array_like)   

df = df.resample('1H').apply(custom_function)

我也有类似的问题,只是简单地使用了scipy-integrate e、 g

import pandas as pd
import numpy as np
from scipy import integrate

data = np.abs(np.random.randn(36000))
ts = pd.Series(data,pd.date_range(start='today', periods=len(data), freq='s'))
ts_int = ts.resample('H').apply(integrate.trapz)