I'd like to fill string missing values in one column with condition based on row after in python. enter image description here
The missing values should have different value with the row after (if we see it with timely perspective), so it should be connect -> disconnect -> connect and so on.
So in this case here I would like to have the Monitoring Desc
missing values to be filled with "disconnect", as the row after is "connect".
I've tried:
df['Monitoring Desc'] = df['Monitoring Desc'].fillna(np.where(df['Monitoring Desc'].shift(1) == "ws_connect", "ws_disconnect", "ws_connect"))
but showed error message: TypeError: "value" parameter must be a scalar, dict or Series, but you passed a "ndarray"
I'm not do this kind of analysis in python, so I can't think of anything else. Maybe there is something to do with loop or function to fill these missing values? Any help would be appreciated.
Code
plz provide input as text table not image.
mapping reverse and ffill
df
Example Code