{ "cells": [ { "cell_type": "markdown", "id": "6f6aa857", "metadata": {}, "source": [ "# Exercise: For each patcher, compute the average number of days they waited between experiments\n", "\n", "Here is how to proceed\n", "1. Use a window function to compute the number of days that elapse between experiment (i.e., the distance between `date`), for each `patcher`. Add that as a new column, `'days from prev'`\n", "2. Compute the average `'days from prev'` per patcher\n", "\n", "With your new awesome vectorization skills, it should take two lines!" ] }, { "cell_type": "code", "execution_count": 1, "id": "8f9bc8b1", "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "\n", "# Set some Pandas options: maximum number of rows/columns it's going to display\n", "pd.set_option('display.max_rows', 1000)\n", "pd.set_option('display.max_columns', 100)" ] }, { "cell_type": "markdown", "id": "1be11d54", "metadata": {}, "source": [ "# Load the neural data" ] }, { "cell_type": "code", "execution_count": 61, "id": "b6b1abff", "metadata": {}, "outputs": [], "source": [ "df = pd.read_csv('shuffled_QC_passed_2024-07-04_collected_v1.csv', parse_dates=['date'])" ] }, { "cell_type": "code", "execution_count": 62, "id": "c0237922", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | OP | \n", "patcher | \n", "date | \n", "slice | \n", "cell_ch | \n", "cell_ID | \n", "day | \n", "treatment | \n", "hrs_incubation | \n", "repatch | \n", "hrs_after_OP | \n", "Rs | \n", "Rin | \n", "resting_potential | \n", "max_spikes | \n", "Rheobase | \n", "AP_heigth | \n", "TH | \n", "max_depol | \n", "max_repol | \n", "membra_time_constant_tau | \n", "capacitance | \n", "comments | \n", "rheo_ramp | \n", "AP_halfwidth | \n", "Rheobse_ramp | \n", "Unnamed: 27 | \n", "rheos_ramp | \n", "comment | \n", "\n", " | high K concentration | \n", "RMP_from_char | \n", "tissue_source | \n", "area | \n", "patient_age | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "OP211209 | \n", "Verji | \n", "2024-03-13 | \n", "S2 | \n", "8 | \n", "21d10S2c8 | \n", "D1 | \n", "Ctrl | \n", "0.0 | \n", "no | \n", "13.298889 | \n", "14.470281 | \n", "166.878916 | \n", "-67.962646 | \n", "34 | \n", "50.0 | \n", "83.190918 | \n", "-36.132812 | \n", "302.124023 | \n", "-72.631836 | \n", "20.75 | \n", "152.623120 | \n", "NaN | \n", "NaN | \n", "0.966102 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "15 mM | \n", "-59.101382 | \n", "Bielefeld | \n", "temporal | \n", "27.0 | \n", "
1 | \n", "OP221024 | \n", "Verji | \n", "2024-06-16 | \n", "S3 | \n", "4 | \n", "22o24S3c4 | \n", "D1 | \n", "Ctrl | \n", "0.0 | \n", "no | \n", "23.964167 | \n", "11.521243 | \n", "137.820797 | \n", "-71.789551 | \n", "41 | \n", "50.0 | \n", "93.322754 | \n", "-42.968750 | \n", "465.820312 | \n", "-83.740234 | \n", "14.85 | \n", "124.324170 | \n", "17 | \n", "NaN | \n", "0.959995 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "8 mM | \n", "-62.265689 | \n", "Bielefeld | \n", "temporal | \n", "42.0 | \n", "
2 | \n", "OP230810 | \n", "Verji | \n", "2024-05-14 | \n", "S2 | \n", "5 | \n", "23810S2c5 | \n", "D1 | \n", "TTX | \n", "0.0 | \n", "no | \n", "7.043056 | \n", "10.120637 | \n", "67.739416 | \n", "-70.629883 | \n", "47 | \n", "100.0 | \n", "91.973877 | \n", "-37.817383 | \n", "415.771484 | \n", "-107.666016 | \n", "13.00 | \n", "228.654858 | \n", "10 | \n", "402.013400 | \n", "0.760052 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "8 mM | \n", "-61.329228 | \n", "Mitte | \n", "temporal | \n", "63.0 | \n", "
3 | \n", "OP230209 | \n", "Verji | \n", "2024-04-27 | \n", "S2_D2 | \n", "3 | \n", "23209S2_D2c3 | \n", "D2 | \n", "high K | \n", "25.0 | \n", "no | \n", "21.848333 | \n", "7.745503 | \n", "43.009610 | \n", "-68.371582 | \n", "31 | \n", "500.0 | \n", "67.163086 | \n", "-29.284668 | \n", "212.036133 | \n", "-61.645508 | \n", "11.05 | \n", "215.784505 | \n", "30 | \n", "672.202407 | \n", "0.958735 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "8 mM | \n", "-62.577472 | \n", "Bielefeld | \n", "temporal | \n", "63.0 | \n", "
4 | \n", "OP240321 | \n", "Verji | \n", "2024-04-11 | \n", "S2 | \n", "4 | \n", "24321S2c4 | \n", "D1 | \n", "Ctrl | \n", "0.0 | \n", "no | \n", "11.530278 | \n", "7.632941 | \n", "32.884808 | \n", "-52.453613 | \n", "21 | \n", "200.0 | \n", "84.008789 | \n", "-36.785889 | \n", "403.442383 | \n", "-71.899414 | \n", "14.80 | \n", "695.791105 | \n", "8 | \n", "NaN | \n", "1.063838 | \n", "324.520817 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "8 mM | \n", "-63.149769 | \n", "Bielefeld | \n", "temporal | \n", "31.0 | \n", "