简体   繁体   English

滚动 window 与应用 function 在 Z3A43B4F88325D2FA94F14Z 数据帧中返回“dict object 不可调用”

[英]Rolling window with apply function reutrns "dict object is not callable" in pandas data frame

For my project, I need to get very granular and continuous measure for heart rate variability through IBI (inter-beat interval) data that I have collected.对于我的项目,我需要通过我收集的 IBI(节拍间间隔)数据对心率变异性进行非常精细和连续的测量。 To do this, I need to window my data applied with a pandas rolling window (size = 30s).为此,我需要 window 我的数据应用 pandas 滚动 window(大小 = 30 秒)。 I define my data frame as such:我这样定义我的数据框:

py_physio_Data = pd.DataFrame(py_physio_DF)

Which yields (this only a snippet of the data):产生(这只是数据的一部分):

Participant参与者 IBI IBI Timestamp时间戳
1 1 526 526 2021-11-10 10:54:15 2021-11-10 10:54:15
1 1 658 658 2021-11-10 10:54:15 2021-11-10 10:54:15
1 1 700 700 2021-11-10 10:54:16 2021-11-10 10:54:16
1 1 695 695 2021-11-10 10:54:17 2021-11-10 10:54:17

Right now I have the data filtered to only include participant one.现在,我将数据过滤为仅包括参与者之一。 So here is the problematic code:所以这是有问题的代码:

import hrvanalysis as hrv
py_physio_Data.index = pd.to_datetime(py_physio_Data["Timestamp"])
py_physio_Data.rolling("30s").apply(func = hrv.get_time_domain_features(py_physio_Data["IBI"]))

I set timestamp as the index column and then I try to apply the function get_time_domain_features().我将时间戳设置为索引列,然后尝试应用 function get_time_domain_features()。

TypeError: 'dict' object is not callable

I cant figure out what the problem is how to fix it.我无法弄清楚问题是如何解决它。 Ive consulted previous posts, tried various syntaxes (see below for examples), but I cant figure out the error.我查阅了以前的帖子,尝试了各种语法(参见下面的示例),但我无法找出错误。 Any help would be appreciated:D任何帮助将不胜感激:D

py_physio_Data.rolling("30s").apply(func = hrv.get_time_domain_features(py_physio_Data))
py_physio_Data.rolling("30s").apply(func = hrv.get_time_domain_features())
py_physio_Data["IBI"].rolling("30s").apply(func = hrv.get_time_domain_features(py_physio_Data["IBI"]))

Try this:尝试这个:

py_physio_Data["IBI"].rolling("30s").apply(hrv.get_time_domain_features);

What you are doing is applying the result of the get_time_domain() function, that you always call with the entire "IBI" column.您正在做的是应用get_time_domain() function 的结果,您始终使用整个“IBI”列调用该结果。 If instead you specify only the function as a callable object, rolling will populate it with a Pandas Series containing the "IBI" data of that iteration, and it will return the resulting dictionary.相反,如果您仅将 function 指定为可调用的 object,则滚动将使用包含该迭代的“IBI”数据的 Pandas 系列填充它,并将返回结果字典。 Before you were calling the dictionary returned as if it was a function, that's why it wasn't returning anything.在您调用字典之前,它就像是 function 一样返回,这就是它没有返回任何内容的原因。

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

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