pandas.core.resample.Resampler.pipe#

Resampler.pipe(func, *args, **kwargs)[源代码]#

应用函数 func 将参数传递给此Ressamer对象,并返回函数的结果。

使用 .pipe 当您希望通过将预期Series、DataFrames、GroupBy或ResSamer对象的函数链接在一起来提高可读性时。与其写作,不如

>>> h(g(f(df.groupby('group')), arg1=a), arg2=b, arg3=c)  

你可以写

>>> (df.groupby('group')
...    .pipe(f)
...    .pipe(g, arg1=a)
...    .pipe(h, arg2=b, arg3=c))  

它的可读性更强。

参数
func(可调用,字符串)的可调用或元组

函数应用于此重采样器对象,或者也可以应用于 (callable, data_keyword) 元组所在位置 data_keyword 是一个字符串,它指示 callable 它需要重采样器对象。

args可迭代,可选

传入的位置参数 func

kwargsDICT,可选

传入的关键字参数词典 func

退货
对象 :的返回类型 func的返回类型

参见

Series.pipe

将带参数的函数应用于系列。

DataFrame.pipe

将带参数的函数应用于数据帧。

apply

将函数应用于每个组,而不是整个重采样器对象。

注意事项

见更多 here

示例

>>> df = pd.DataFrame({'A': [1, 2, 3, 4]},
...                   index=pd.date_range('2012-08-02', periods=4))
>>> df
            A
2012-08-02  1
2012-08-03  2
2012-08-04  3
2012-08-05  4

要一次性获得每个2天周期的最大值和最小值之间的差值,您可以执行以下操作

>>> df.resample('2D').pipe(lambda x: x.max() - x.min())
            A
2012-08-02  1
2012-08-04  1