For a DataFrame such as
import pandas as pd
import numpy as np
times = [21 , 34, 37, 40, 55, 65, 67, 84, 88, 90 , 91, 97, 104,105, 108]
names = ['bob', 'alice', 'bob', np.NaN , 'ali', 'alice', np.NaN , 'ali', 'moji', 'ali', 'moji', np.NaN , 'bob', 'bob', 'bob']
actions = ['enter', 'enter', 'search', 'search', 'enter', 'search', 'purchase', 'exit', 'enter' , 'enter', 'search', 'purchase', 'exit', 'enter', 'purchase']
df = pd.DataFrame({'name' : names , 'action': actions, 'time' : times})
I want only rows where name is NaN and also row exactly before and exactly after such rows. I could do this by for and if commands. but is there any more neat way to do this?