Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: Consecutive NaN larger than threshold in Pandas DataFrame

Noque:

I would like to find those indexes of consecutive NaN in a Pandas DataFrame with more than 3 consecutive NaN returning their size. That is:


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

Should return something like (58238, 6). The actual format of the return doesn't matter too much. I have found the following.


df.a.isnull().astype(int).groupby(df.a.notnull().astype(int).cumsum()).sum()

But it is not returning the right values per index. This question might be very similar to Identifying consecutive NaN's with pandas but any help would very appreciated as I am a total noob in Pandas.



Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: Consecutive NaN larger than threshold in Pandas DataFrame

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×