With a list containing some missing values such as this:
[10, 11, 12,np.nan, 14, np.nan, 16, 17, np.nan, 19, np.nan]
How can you subset the values that are positioned between two missing (nan) values?
I know how to do it with a for loop :
# imports
import numpy as np
# input
lst=[10,11,12,np.nan, 14, np.nan, 16, 17, np.nan, 19, np.nan]
# define an empty list and build on that in a For Loop
subset=[]
for i, elem in enumerate(lst):
if np.isnan(lst[i-1]) and np.isnan(lst[i+1]):
subset.extend([elem])
print(subset)
# output
# [14, 19]
Any suggestions on how to do this in a less cumbersome way?