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. To do this, I need to window my data applied with a pandas rolling window (size = 30s). 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 | Timestamp |
---|---|---|
1 | 526 | 2021-11-10 10:54:15 |
1 | 658 | 2021-11-10 10:54:15 |
1 | 700 | 2021-11-10 10:54:16 |
1 | 695 | 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().
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
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. 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. Before you were calling the dictionary returned as if it was a function, that's why it wasn't returning anything.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.