import pandas as pdimport numpy as npimport itertoolsa = 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
结果是
[1, 3, 2]
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)