Have a dataset with 5 rows and 3 columns. Index is resampled at 2 seconds. So I want to calculate the rolling median at frequency =2.
so while calculating the median at frequency 2 it should look for first 2 rows and all 3 columns like B, c and d to come up with a median. Similarly the second window should consider both rows and all 3 columns B ,c and d to come up with the median.
df = pd.DataFrame({'B': [0, 1, 2, np.nan, 4],'c': [2,4,7,8,9],'d': [2,8,7,5,9]},
index = [pd.Timestamp('20130101 09:00:00'),
pd.Timestamp('20130101 09:00:02'),
pd.Timestamp('20130101 09:00:03'),
pd.Timestamp('20130101 09:00:05'),
pd.Timestamp('20130101 09:00:06')])
In pandas we can pass only one column in rolling window , how to pass multiple columns. so that it looks for all the elements present in that rows amongst all columns.
df.B.rolling('2s').median()
I expected the output to be :
2013-01-01 09:00:00 Nan
2013-01-01 09:00:02 1.0
2013-01-01 09:00:03 5.5
and so on
how can we pass multiple columns in the pandas rolling function