17 KiB
17 KiB
Exercise: For each patcher, compute the average number of days they waited between experiments¶
Here is how to proceed
- Use a window function to compute the number of days that elapse between experiment (i.e., the distance between
date
), for eachpatcher
. Add that as a new column,'days from prev'
- Compute the average
'days from prev'
per patcher
With your new awesome vectorization skills, it should take two lines!
In [1]:
import pandas as pd
# Set some Pandas options: maximum number of rows/columns it's going to display
pd.set_option('display.max_rows', 1000)
pd.set_option('display.max_columns', 100)
Load the neural data¶
In [61]:
df = pd.read_csv('shuffled_QC_passed_2024-07-04_collected_v1.csv', parse_dates=['date'])
In [62]:
df.head()
Out[62]:
In [64]:
df['days from prev'] = df['date'] - df.sort_values('date').groupby('patcher')['date'].shift()
In [68]:
df.sort_values(['patcher', 'date'])[['patcher', 'date', 'days from prev']].head()
Out[68]:
In [74]:
df.groupby('patcher')['days from prev'].mean()
Out[74]:
In [ ]:
In [ ]:
In [ ]: