更新时间:2023-11-20 19:36:28
您可以使用numpy.split
,然后过滤结果列表.这是一个示例,假定带有值的列标记为"value"
:
You can use numpy.split
and then filter the resulting list. Here is one example assuming that the column with the values is labeled "value"
:
events = np.split(df, np.where(np.isnan(df.value))[0])
# removing NaN entries
events = [ev[~np.isnan(ev.value)] for ev in events if not isinstance(ev, np.ndarray)]
# removing empty DataFrames
events = [ev for ev in events if not ev.empty]
您将拥有一个列表,其中所有事件均由NaN
值分隔.
You will have a list with all the events separated by the NaN
values.