I am wondering how to save previous result, that matched certain conditions (df['condition'] in every row that follows. I know how to do it with for loop, but I know I should avoid them when working with pandas.
Below is an example. column df['desired_result] represents what I want to achieve.
import pandas as pd
import numpy as np
dates = pd.date_range('1/1/2000', periods=10)
values = np.arange(10.0, 20.0, 1.0)
data = {'date': dates, 'value': values}
df = pd.DataFrame.from_dict(data)
df['condition'] = [False, False, True, True, False, True, False, False, True, False]
df_valid = df[df['condition']]
df['desired_result'] = [np.nan, np.nan, 12, 13, 13, 15, 15, 15, 18, 18]