Pandas: Run Length Of Nan Holes
I have hundreds of timeseries objects with 100000's of entries in each. Some percentage of the data entries are missing (NaN). It is important to my application whether those are s
Solution 1:
import pandas as pd
import numpy as np
import itertools
a = pd.Series([1, 2, 3, np.nan, 4, np.nan, np.nan, np.nan, 5, np.nan, np.nan])
len_holes = [len(list(g)) for k, g in itertools.groupby(a, lambda x: np.isnan(x)) if k]
print len_holes
results in
[1, 3, 2]
Post a Comment for "Pandas: Run Length Of Nan Holes"