我想在Pandas数据帧中找到连续NaN的那些索引,其中超过3个连续NaN返回它们的大小。即:
58234 NaN
58235 NaN
58236 0.424323
58237 0.424323
58238 NaN
58239 NaN
58240 NaN
58241 NaN
58242 NaN
58245 NaN
58246 1.483380
58247 1.483380
应该返回类似(58238,6)的值。返回的实际格式并不重要。我发现了以下内容。在
^{pr2}$但它没有为每个索引返回正确的值。这个问题可能非常类似于Identifying consecutive NaN's with pandas 但如果有人帮我,我会非常感激的,因为我在熊猫界是个十足的无赖。在
我把台阶弄坏了:
所以这会有点慢,但我也是熊猫和Python的初学者。它是超级丑陋的,但不知道你的数据集我会怎么做。在
因为它会在indx上运行,它会找到按顺序运行的每一个。唯一的问题是,如果你不想每次一行有三个(连续6次锯),你就必须修改一下代码,不把current consec更改为0,并创建一个pass语句。在
抱歉,这是一个新的答案,但它可能会工作,如果你找到更快的东西,让我知道,因为我很乐意将它添加到我的知识库。在
祝你好运
安迪M
假设
df
将这些列命名为两列:A
,B
,这里有一种矢量化方法-样本输入,输出-
^{pr2}$使用
^{3}$thresh = 2
,我们有-相关问题 更多 >
编程相关推荐