簡體   English   中英

滾動 window 與應用 function 在 Z3A43B4F88325D2FA94F14Z 數據幀中返回“dict object 不可調用”

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

對於我的項目,我需要通過我收集的 IBI(節拍間間隔)數據對心率變異性進行非常精細和連續的測量。 為此,我需要 window 我的數據應用 pandas 滾動 window(大小 = 30 秒)。 我這樣定義我的數據框:

py_physio_Data = pd.DataFrame(py_physio_DF)

產生(這只是數據的一部分):

參與者 IBI 時間戳
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

現在,我將數據過濾為僅包括參與者之一。 所以這是有問題的代碼:

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

我將時間戳設置為索引列,然后嘗試應用 function get_time_domain_features()。

TypeError: 'dict' object is not callable

我無法弄清楚問題是如何解決它。 我查閱了以前的帖子,嘗試了各種語法(參見下面的示例),但我無法找出錯誤。 任何幫助將不勝感激: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"]))

嘗試這個:

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

您正在做的是應用get_time_domain() function 的結果,您始終使用整個“IBI”列調用該結果。 相反,如果您僅將 function 指定為可調用的 object,則滾動將使用包含該迭代的“IBI”數據的 Pandas 系列填充它,並將返回結果字典。 在您調用字典之前,它就像是 function 一樣返回,這就是它沒有返回任何內容的原因。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM