7.8 KiB
7.8 KiB
Window functions for tabular data¶
In [1]:
import pandas as pd
Load experimental data¶
In [2]:
df = pd.read_csv('timed_responses.csv', index_col=0)
In [3]:
df
Out[3]:
Split-apply-combine operations return one aggregated value per group¶
In [ ]:
df.groupby('subject_id')['accuracy'].max()
In [ ]:
However, for some calculations we need to have a value per row¶
For example: for each subject, rank the responses by decreasing accuracy
In [ ]:
In many cases, a window functions is combined with a sorting operation¶
For example: for each subject, count the number of "LEFT" responses up until any moment in the experiment
In [ ]:
Window functions are also useful to compute changes in the data for each group¶
In this case, the window function often uses the shift(n)
method that lags the data by n
rows
In [ ]:
In [ ]:
In [ ]: