I have code that looks like this
d = pd.DataFrame.from_dict({'ix':[0,1,2,3,4,5], 'val': [1,-2,5,4,9,6]})
d['first'] = d['val'].rolling(3).agg(lambda rows: rows[0])
Per the suggestion here Taking first and last value in a rolling window, but I am getting the following error:
ValueError: 0 is not in range
Any idea how I can get the first and last value from a rolling window in pandas
?