2024-heraklion-data/exercises/pandas_intro/pandas_intro_solution.ipynb

1488 lines
49 KiB
Plaintext
Raw Normal View History

2024-08-27 14:27:53 +02:00
{
"cells": [
{
"cell_type": "markdown",
"id": "560f48cd",
"metadata": {},
"source": [
"# Exercise: Have a look at the neural data using Pandas"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "f7777604",
"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": "6494fb41",
"metadata": {},
"source": [
"# Load electrophysiology data"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9ca3bec6",
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('../../data/QC_passed_2024-07-04_collected.csv')"
]
},
{
"cell_type": "markdown",
"id": "0d78a63e",
"metadata": {},
"source": [
"## 1. How many rows/columns does the data set have?"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "291ebbfb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(827, 31)"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.shape"
]
},
{
"cell_type": "markdown",
"id": "0fab635e",
"metadata": {},
"source": [
"## 2. Display the first 5 rows of the DataFrame"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "908f60ae",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>OP</th>\n",
" <th>filename</th>\n",
" <th>slice</th>\n",
" <th>cell_ch</th>\n",
" <th>cell_ID</th>\n",
" <th>day</th>\n",
" <th>treatment</th>\n",
" <th>hrs_incubation</th>\n",
" <th>repatch</th>\n",
" <th>hrs_after_OP</th>\n",
" <th>Rs</th>\n",
" <th>Rin</th>\n",
" <th>resting_potential</th>\n",
" <th>max_spikes</th>\n",
" <th>Rheobase</th>\n",
" <th>AP_heigth</th>\n",
" <th>TH</th>\n",
" <th>max_depol</th>\n",
" <th>max_repol</th>\n",
" <th>membra_time_constant_tau</th>\n",
" <th>capacitance</th>\n",
" <th>comments</th>\n",
" <th>rheo_ramp</th>\n",
" <th>AP_halfwidth</th>\n",
" <th>Rheobse_ramp</th>\n",
" <th>Unnamed: 27</th>\n",
" <th>rheos_ramp</th>\n",
" <th>comment</th>\n",
" <th></th>\n",
" <th>high K concentration</th>\n",
" <th>RMP_from_char</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>OP230420</td>\n",
" <td>23420003.abf</td>\n",
" <td>S1</td>\n",
" <td>1</td>\n",
" <td>23420S1c1</td>\n",
" <td>D1</td>\n",
" <td>TTX</td>\n",
" <td>0.0</td>\n",
" <td>no</td>\n",
" <td>10.416389</td>\n",
" <td>6.675643</td>\n",
" <td>39.025301</td>\n",
" <td>-74.285889</td>\n",
" <td>24</td>\n",
" <td>200.0</td>\n",
" <td>80.749512</td>\n",
" <td>-35.278320</td>\n",
" <td>336.181641</td>\n",
" <td>-60.791016</td>\n",
" <td>19.40</td>\n",
" <td>510.601767</td>\n",
" <td>0</td>\n",
" <td>753.380113</td>\n",
" <td>1.151009</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-61.828554</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>OP230420</td>\n",
" <td>23420003.abf</td>\n",
" <td>S1</td>\n",
" <td>3</td>\n",
" <td>23420S1c3</td>\n",
" <td>D1</td>\n",
" <td>TTX</td>\n",
" <td>0.0</td>\n",
" <td>no</td>\n",
" <td>10.416389</td>\n",
" <td>7.867174</td>\n",
" <td>48.728367</td>\n",
" <td>-69.573975</td>\n",
" <td>26</td>\n",
" <td>300.0</td>\n",
" <td>78.448486</td>\n",
" <td>-32.043457</td>\n",
" <td>350.097656</td>\n",
" <td>-67.138672</td>\n",
" <td>17.30</td>\n",
" <td>393.397918</td>\n",
" <td>1</td>\n",
" <td>585.102837</td>\n",
" <td>1.006321</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-60.460298</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>OP230420</td>\n",
" <td>23420003.abf</td>\n",
" <td>S1</td>\n",
" <td>6</td>\n",
" <td>23420S1c6</td>\n",
" <td>D1</td>\n",
" <td>TTX</td>\n",
" <td>0.0</td>\n",
" <td>no</td>\n",
" <td>10.416389</td>\n",
" <td>8.820134</td>\n",
" <td>35.971082</td>\n",
" <td>-54.956055</td>\n",
" <td>22</td>\n",
" <td>300.0</td>\n",
" <td>76.660156</td>\n",
" <td>-29.827881</td>\n",
" <td>270.629883</td>\n",
" <td>-52.246094</td>\n",
" <td>14.85</td>\n",
" <td>426.098774</td>\n",
" <td>3</td>\n",
" <td>173.915797</td>\n",
" <td>1.266335</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-59.615979</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>OP230420</td>\n",
" <td>23420003.abf</td>\n",
" <td>S1</td>\n",
" <td>7</td>\n",
" <td>23420S1c7</td>\n",
" <td>D1</td>\n",
" <td>TTX</td>\n",
" <td>0.0</td>\n",
" <td>yes</td>\n",
" <td>10.416389</td>\n",
" <td>7.269195</td>\n",
" <td>39.186101</td>\n",
" <td>-69.268799</td>\n",
" <td>24</td>\n",
" <td>300.0</td>\n",
" <td>75.030518</td>\n",
" <td>-29.699707</td>\n",
" <td>242.553711</td>\n",
" <td>-71.411133</td>\n",
" <td>17.15</td>\n",
" <td>478.273362</td>\n",
" <td>4</td>\n",
" <td>598.079936</td>\n",
" <td>0.994396</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-61.173839</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>OP230420</td>\n",
" <td>23420003.abf</td>\n",
" <td>S1</td>\n",
" <td>8</td>\n",
" <td>23420S1c8</td>\n",
" <td>D1</td>\n",
" <td>TTX</td>\n",
" <td>0.0</td>\n",
" <td>yes</td>\n",
" <td>10.416389</td>\n",
" <td>6.000400</td>\n",
" <td>31.599917</td>\n",
" <td>-70.550537</td>\n",
" <td>22</td>\n",
" <td>350.0</td>\n",
" <td>81.011963</td>\n",
" <td>-33.068848</td>\n",
" <td>309.448242</td>\n",
" <td>-61.401367</td>\n",
" <td>16.65</td>\n",
" <td>575.513924</td>\n",
" <td>5</td>\n",
" <td>786.927898</td>\n",
" <td>1.182830</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-60.956350</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" OP filename slice cell_ch cell_ID day treatment \\\n",
"0 OP230420 23420003.abf S1 1 23420S1c1 D1 TTX \n",
"1 OP230420 23420003.abf S1 3 23420S1c3 D1 TTX \n",
"2 OP230420 23420003.abf S1 6 23420S1c6 D1 TTX \n",
"3 OP230420 23420003.abf S1 7 23420S1c7 D1 TTX \n",
"4 OP230420 23420003.abf S1 8 23420S1c8 D1 TTX \n",
"\n",
" hrs_incubation repatch hrs_after_OP Rs Rin \\\n",
"0 0.0 no 10.416389 6.675643 39.025301 \n",
"1 0.0 no 10.416389 7.867174 48.728367 \n",
"2 0.0 no 10.416389 8.820134 35.971082 \n",
"3 0.0 yes 10.416389 7.269195 39.186101 \n",
"4 0.0 yes 10.416389 6.000400 31.599917 \n",
"\n",
" resting_potential max_spikes Rheobase AP_heigth TH max_depol \\\n",
"0 -74.285889 24 200.0 80.749512 -35.278320 336.181641 \n",
"1 -69.573975 26 300.0 78.448486 -32.043457 350.097656 \n",
"2 -54.956055 22 300.0 76.660156 -29.827881 270.629883 \n",
"3 -69.268799 24 300.0 75.030518 -29.699707 242.553711 \n",
"4 -70.550537 22 350.0 81.011963 -33.068848 309.448242 \n",
"\n",
" max_repol membra_time_constant_tau capacitance comments rheo_ramp \\\n",
"0 -60.791016 19.40 510.601767 0 753.380113 \n",
"1 -67.138672 17.30 393.397918 1 585.102837 \n",
"2 -52.246094 14.85 426.098774 3 173.915797 \n",
"3 -71.411133 17.15 478.273362 4 598.079936 \n",
"4 -61.401367 16.65 575.513924 5 786.927898 \n",
"\n",
" AP_halfwidth Rheobse_ramp Unnamed: 27 rheos_ramp comment \\\n",
"0 1.151009 NaN NaN NaN NaN NaN \n",
"1 1.006321 NaN NaN NaN NaN NaN \n",
"2 1.266335 NaN NaN NaN NaN NaN \n",
"3 0.994396 NaN NaN NaN NaN NaN \n",
"4 1.182830 NaN NaN NaN NaN NaN \n",
"\n",
" high K concentration RMP_from_char \n",
"0 8 mM -61.828554 \n",
"1 8 mM -60.460298 \n",
"2 8 mM -59.615979 \n",
"3 8 mM -61.173839 \n",
"4 8 mM -60.956350 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "markdown",
"id": "deecdfa0",
"metadata": {},
"source": [
"## 3. Display the names and dtypes of all the columns"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "025779f0",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"OP object\n",
"filename object\n",
"slice object\n",
"cell_ch int64\n",
"cell_ID object\n",
"day object\n",
"treatment object\n",
"hrs_incubation float64\n",
"repatch object\n",
"hrs_after_OP float64\n",
"Rs float64\n",
"Rin float64\n",
"resting_potential float64\n",
"max_spikes int64\n",
"Rheobase float64\n",
"AP_heigth float64\n",
"TH float64\n",
"max_depol float64\n",
"max_repol float64\n",
"membra_time_constant_tau float64\n",
"capacitance float64\n",
"comments object\n",
"rheo_ramp float64\n",
"AP_halfwidth float64\n",
"Rheobse_ramp float64\n",
"Unnamed: 27 float64\n",
"rheos_ramp float64\n",
"comment object\n",
" float64\n",
"high K concentration object\n",
"RMP_from_char float64\n",
"dtype: object"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dtypes"
]
},
{
"cell_type": "markdown",
"id": "411f4228",
"metadata": {},
"source": [
"## 4. Display the unique values of the `high K concentration` and of the `treatment` columns"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "a2248e7b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['8 mM', '15 mM'], dtype=object)"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['high K concentration'].unique()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "4d0f3708",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['TTX', 'high K', 'Ctrl', 'wash in high K'], dtype=object)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['treatment'].unique()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "f3154259",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"44"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['OP'].nunique()"
]
},
{
"cell_type": "markdown",
"id": "1e395e8d",
"metadata": {},
"source": [
"## 5. Display the main statistics of the `max_spikes` column"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "0d196291",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"count 827.000000\n",
"mean 27.920193\n",
"std 57.997378\n",
"min 0.000000\n",
"25% 19.000000\n",
"50% 26.000000\n",
"75% 33.000000\n",
"max 1664.000000\n",
"Name: max_spikes, dtype: float64"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['max_spikes'].describe()"
]
},
{
"cell_type": "markdown",
"id": "c8c9f6b2",
"metadata": {},
"source": [
"## 6. Show all the rows where the max number of spikes is larger than 50"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "d907492d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>OP</th>\n",
" <th>filename</th>\n",
" <th>slice</th>\n",
" <th>cell_ch</th>\n",
" <th>cell_ID</th>\n",
" <th>day</th>\n",
" <th>treatment</th>\n",
" <th>hrs_incubation</th>\n",
" <th>repatch</th>\n",
" <th>hrs_after_OP</th>\n",
" <th>Rs</th>\n",
" <th>Rin</th>\n",
" <th>resting_potential</th>\n",
" <th>max_spikes</th>\n",
" <th>Rheobase</th>\n",
" <th>AP_heigth</th>\n",
" <th>TH</th>\n",
" <th>max_depol</th>\n",
" <th>max_repol</th>\n",
" <th>membra_time_constant_tau</th>\n",
" <th>capacitance</th>\n",
" <th>comments</th>\n",
" <th>rheo_ramp</th>\n",
" <th>AP_halfwidth</th>\n",
" <th>Rheobse_ramp</th>\n",
" <th>Unnamed: 27</th>\n",
" <th>rheos_ramp</th>\n",
" <th>comment</th>\n",
" <th></th>\n",
" <th>high K concentration</th>\n",
" <th>RMP_from_char</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>70</th>\n",
" <td>OP231130</td>\n",
" <td>23n30003.abf</td>\n",
" <td>S1</td>\n",
" <td>1</td>\n",
" <td>23n30S1c1</td>\n",
" <td>D1</td>\n",
" <td>Ctrl</td>\n",
" <td>0.0</td>\n",
" <td>yes</td>\n",
" <td>11.992778</td>\n",
" <td>15.627081</td>\n",
" <td>58.666581</td>\n",
" <td>-78.060913</td>\n",
" <td>55</td>\n",
" <td>300.0</td>\n",
" <td>88.775635</td>\n",
" <td>-41.577148</td>\n",
" <td>352.294922</td>\n",
" <td>-103.515625</td>\n",
" <td>13.80</td>\n",
" <td>329.350619</td>\n",
" <td>0</td>\n",
" <td>NaN</td>\n",
" <td>0.811086</td>\n",
" <td>351.581719</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-71.584465</td>\n",
" </tr>\n",
" <tr>\n",
" <th>74</th>\n",
" <td>OP231130</td>\n",
" <td>23n30037.abf</td>\n",
" <td>S1_D2</td>\n",
" <td>2</td>\n",
" <td>23n30S1_D2c2</td>\n",
" <td>D2</td>\n",
" <td>wash in high K</td>\n",
" <td>21.0</td>\n",
" <td>no</td>\n",
" <td>32.699444</td>\n",
" <td>7.426442</td>\n",
" <td>65.804793</td>\n",
" <td>-67.544556</td>\n",
" <td>61</td>\n",
" <td>250.0</td>\n",
" <td>77.716064</td>\n",
" <td>-36.505127</td>\n",
" <td>246.459961</td>\n",
" <td>-74.340820</td>\n",
" <td>12.50</td>\n",
" <td>200.293398</td>\n",
" <td>8; exclude; Rs_end &gt; 30</td>\n",
" <td>NaN</td>\n",
" <td>0.950158</td>\n",
" <td>322.090736</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-59.579331</td>\n",
" </tr>\n",
" <tr>\n",
" <th>262</th>\n",
" <td>OP230808</td>\n",
" <td>23808003.abf</td>\n",
" <td>S1</td>\n",
" <td>6</td>\n",
" <td>23808S1c6</td>\n",
" <td>D1</td>\n",
" <td>TTX</td>\n",
" <td>0.0</td>\n",
" <td>no</td>\n",
" <td>8.163333</td>\n",
" <td>10.394754</td>\n",
" <td>106.082649</td>\n",
" <td>-83.300781</td>\n",
" <td>1664</td>\n",
" <td>-300.0</td>\n",
" <td>71.081543</td>\n",
" <td>-15.057373</td>\n",
" <td>237.426758</td>\n",
" <td>-69.702148</td>\n",
" <td>13.05</td>\n",
" <td>98.940861</td>\n",
" <td>5</td>\n",
" <td>NaN</td>\n",
" <td>1.025354</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-32.684415</td>\n",
" </tr>\n",
" <tr>\n",
" <th>321</th>\n",
" <td>OP230209</td>\n",
" <td>23209012.abf</td>\n",
" <td>S2</td>\n",
" <td>5</td>\n",
" <td>23209S2c5</td>\n",
" <td>D1</td>\n",
" <td>high K</td>\n",
" <td>0.0</td>\n",
" <td>no</td>\n",
" <td>-2.874722</td>\n",
" <td>8.525730</td>\n",
" <td>81.231493</td>\n",
" <td>-69.049072</td>\n",
" <td>53</td>\n",
" <td>100.0</td>\n",
" <td>82.275391</td>\n",
" <td>-34.912109</td>\n",
" <td>365.478516</td>\n",
" <td>-98.266602</td>\n",
" <td>13.05</td>\n",
" <td>141.831642</td>\n",
" <td>8</td>\n",
" <td>192.024601</td>\n",
" <td>0.713136</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-58.246034</td>\n",
" </tr>\n",
" <tr>\n",
" <th>396</th>\n",
" <td>OP230810</td>\n",
" <td>23810004.abf</td>\n",
" <td>S1</td>\n",
" <td>5</td>\n",
" <td>23810S1c5</td>\n",
" <td>D1</td>\n",
" <td>high K</td>\n",
" <td>0.0</td>\n",
" <td>yes</td>\n",
" <td>5.660833</td>\n",
" <td>25.468412</td>\n",
" <td>79.043216</td>\n",
" <td>-65.155029</td>\n",
" <td>55</td>\n",
" <td>100.0</td>\n",
" <td>85.491943</td>\n",
" <td>-43.072510</td>\n",
" <td>389.770508</td>\n",
" <td>-80.078125</td>\n",
" <td>11.45</td>\n",
" <td>241.592788</td>\n",
" <td>3</td>\n",
" <td>224.587500</td>\n",
" <td>0.966593</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-60.860893</td>\n",
" </tr>\n",
" <tr>\n",
" <th>397</th>\n",
" <td>OP230810</td>\n",
" <td>23810004.abf</td>\n",
" <td>S1</td>\n",
" <td>7</td>\n",
" <td>23810S1c7</td>\n",
" <td>D1</td>\n",
" <td>high K</td>\n",
" <td>0.0</td>\n",
" <td>yes</td>\n",
" <td>5.660833</td>\n",
" <td>26.756530</td>\n",
" <td>74.709503</td>\n",
" <td>-64.855957</td>\n",
" <td>53</td>\n",
" <td>150.0</td>\n",
" <td>90.942383</td>\n",
" <td>-42.932129</td>\n",
" <td>423.950195</td>\n",
" <td>-83.007812</td>\n",
" <td>9.10</td>\n",
" <td>239.316854</td>\n",
" <td>5</td>\n",
" <td>307.540300</td>\n",
" <td>0.965371</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-61.513494</td>\n",
" </tr>\n",
" <tr>\n",
" <th>398</th>\n",
" <td>OP230810</td>\n",
" <td>23810004.abf</td>\n",
" <td>S1</td>\n",
" <td>8</td>\n",
" <td>23810S1c8</td>\n",
" <td>D1</td>\n",
" <td>high K</td>\n",
" <td>0.0</td>\n",
" <td>no</td>\n",
" <td>5.660833</td>\n",
" <td>18.023665</td>\n",
" <td>63.532613</td>\n",
" <td>-61.413574</td>\n",
" <td>55</td>\n",
" <td>200.0</td>\n",
" <td>84.509277</td>\n",
" <td>-39.605713</td>\n",
" <td>339.843750</td>\n",
" <td>-77.392578</td>\n",
" <td>7.10</td>\n",
" <td>146.691551</td>\n",
" <td>6</td>\n",
" <td>199.506700</td>\n",
" <td>1.043352</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-62.291177</td>\n",
" </tr>\n",
" <tr>\n",
" <th>558</th>\n",
" <td>OP230314</td>\n",
" <td>23314003.abf</td>\n",
" <td>S1</td>\n",
" <td>8</td>\n",
" <td>23314S1c8</td>\n",
" <td>D1</td>\n",
" <td>high K</td>\n",
" <td>0.0</td>\n",
" <td>no</td>\n",
" <td>5.940833</td>\n",
" <td>22.054204</td>\n",
" <td>97.596130</td>\n",
" <td>-67.358398</td>\n",
" <td>52</td>\n",
" <td>100.0</td>\n",
" <td>79.431152</td>\n",
" <td>-41.333008</td>\n",
" <td>325.073242</td>\n",
" <td>-111.572266</td>\n",
" <td>13.30</td>\n",
" <td>186.404790</td>\n",
" <td>5</td>\n",
" <td>NaN</td>\n",
" <td>0.776089</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>201.505075</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-61.035575</td>\n",
" </tr>\n",
" <tr>\n",
" <th>646</th>\n",
" <td>OP240117</td>\n",
" <td>24118004.abf</td>\n",
" <td>S2_D2</td>\n",
" <td>4</td>\n",
" <td>24117S2_D2c4</td>\n",
" <td>D1</td>\n",
" <td>Ctrl</td>\n",
" <td>20.0</td>\n",
" <td>no</td>\n",
" <td>26.424200</td>\n",
" <td>17.188385</td>\n",
" <td>139.095453</td>\n",
" <td>-76.916504</td>\n",
" <td>61</td>\n",
" <td>100.0</td>\n",
" <td>78.436279</td>\n",
" <td>-40.686035</td>\n",
" <td>316.040039</td>\n",
" <td>-95.092773</td>\n",
" <td>19.80</td>\n",
" <td>201.367598</td>\n",
" <td>3</td>\n",
" <td>NaN</td>\n",
" <td>0.740537</td>\n",
" <td>295.539851</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-59.561161</td>\n",
" </tr>\n",
" <tr>\n",
" <th>647</th>\n",
" <td>OP240117</td>\n",
" <td>24118004.abf</td>\n",
" <td>S2_D2</td>\n",
" <td>5</td>\n",
" <td>24117S2_D2c5</td>\n",
" <td>D1</td>\n",
" <td>Ctrl</td>\n",
" <td>20.0</td>\n",
" <td>no</td>\n",
" <td>26.424200</td>\n",
" <td>27.929918</td>\n",
" <td>140.091217</td>\n",
" <td>-70.422363</td>\n",
" <td>56</td>\n",
" <td>100.0</td>\n",
" <td>82.684326</td>\n",
" <td>-44.421387</td>\n",
" <td>325.561523</td>\n",
" <td>-96.923828</td>\n",
" <td>18.85</td>\n",
" <td>226.172391</td>\n",
" <td>4</td>\n",
" <td>NaN</td>\n",
" <td>0.769121</td>\n",
" <td>207.006900</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-60.495223</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" OP filename slice cell_ch cell_ID day treatment \\\n",
"70 OP231130 23n30003.abf S1 1 23n30S1c1 D1 Ctrl \n",
"74 OP231130 23n30037.abf S1_D2 2 23n30S1_D2c2 D2 wash in high K \n",
"262 OP230808 23808003.abf S1 6 23808S1c6 D1 TTX \n",
"321 OP230209 23209012.abf S2 5 23209S2c5 D1 high K \n",
"396 OP230810 23810004.abf S1 5 23810S1c5 D1 high K \n",
"397 OP230810 23810004.abf S1 7 23810S1c7 D1 high K \n",
"398 OP230810 23810004.abf S1 8 23810S1c8 D1 high K \n",
"558 OP230314 23314003.abf S1 8 23314S1c8 D1 high K \n",
"646 OP240117 24118004.abf S2_D2 4 24117S2_D2c4 D1 Ctrl \n",
"647 OP240117 24118004.abf S2_D2 5 24117S2_D2c5 D1 Ctrl \n",
"\n",
" hrs_incubation repatch hrs_after_OP Rs Rin \\\n",
"70 0.0 yes 11.992778 15.627081 58.666581 \n",
"74 21.0 no 32.699444 7.426442 65.804793 \n",
"262 0.0 no 8.163333 10.394754 106.082649 \n",
"321 0.0 no -2.874722 8.525730 81.231493 \n",
"396 0.0 yes 5.660833 25.468412 79.043216 \n",
"397 0.0 yes 5.660833 26.756530 74.709503 \n",
"398 0.0 no 5.660833 18.023665 63.532613 \n",
"558 0.0 no 5.940833 22.054204 97.596130 \n",
"646 20.0 no 26.424200 17.188385 139.095453 \n",
"647 20.0 no 26.424200 27.929918 140.091217 \n",
"\n",
" resting_potential max_spikes Rheobase AP_heigth TH \\\n",
"70 -78.060913 55 300.0 88.775635 -41.577148 \n",
"74 -67.544556 61 250.0 77.716064 -36.505127 \n",
"262 -83.300781 1664 -300.0 71.081543 -15.057373 \n",
"321 -69.049072 53 100.0 82.275391 -34.912109 \n",
"396 -65.155029 55 100.0 85.491943 -43.072510 \n",
"397 -64.855957 53 150.0 90.942383 -42.932129 \n",
"398 -61.413574 55 200.0 84.509277 -39.605713 \n",
"558 -67.358398 52 100.0 79.431152 -41.333008 \n",
"646 -76.916504 61 100.0 78.436279 -40.686035 \n",
"647 -70.422363 56 100.0 82.684326 -44.421387 \n",
"\n",
" max_depol max_repol membra_time_constant_tau capacitance \\\n",
"70 352.294922 -103.515625 13.80 329.350619 \n",
"74 246.459961 -74.340820 12.50 200.293398 \n",
"262 237.426758 -69.702148 13.05 98.940861 \n",
"321 365.478516 -98.266602 13.05 141.831642 \n",
"396 389.770508 -80.078125 11.45 241.592788 \n",
"397 423.950195 -83.007812 9.10 239.316854 \n",
"398 339.843750 -77.392578 7.10 146.691551 \n",
"558 325.073242 -111.572266 13.30 186.404790 \n",
"646 316.040039 -95.092773 19.80 201.367598 \n",
"647 325.561523 -96.923828 18.85 226.172391 \n",
"\n",
" comments rheo_ramp AP_halfwidth Rheobse_ramp \\\n",
"70 0 NaN 0.811086 351.581719 \n",
"74 8; exclude; Rs_end > 30 NaN 0.950158 322.090736 \n",
"262 5 NaN 1.025354 NaN \n",
"321 8 192.024601 0.713136 NaN \n",
"396 3 224.587500 0.966593 NaN \n",
"397 5 307.540300 0.965371 NaN \n",
"398 6 199.506700 1.043352 NaN \n",
"558 5 NaN 0.776089 NaN \n",
"646 3 NaN 0.740537 295.539851 \n",
"647 4 NaN 0.769121 207.006900 \n",
"\n",
" Unnamed: 27 rheos_ramp comment high K concentration RMP_from_char \n",
"70 NaN NaN NaN NaN 8 mM -71.584465 \n",
"74 NaN NaN NaN NaN 8 mM -59.579331 \n",
"262 NaN NaN NaN NaN 8 mM -32.684415 \n",
"321 NaN NaN NaN NaN 8 mM -58.246034 \n",
"396 NaN NaN NaN NaN 8 mM -60.860893 \n",
"397 NaN NaN NaN NaN 8 mM -61.513494 \n",
"398 NaN NaN NaN NaN 8 mM -62.291177 \n",
"558 NaN 201.505075 NaN NaN 8 mM -61.035575 \n",
"646 NaN NaN NaN NaN 8 mM -59.561161 \n",
"647 NaN NaN NaN NaN 8 mM -60.495223 "
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[df['max_spikes'] > 50]"
]
},
{
"cell_type": "markdown",
"id": "ce9ff32b",
"metadata": {},
"source": [
"## 7. Display the main statistics of `'max_spikes'`, for the rows where `high K concentration` is `8 mM` and `15 mM` (separately)\n",
"\n",
"Are the distributions any different?"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "5924179e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"count 474.000000\n",
"mean 30.955696\n",
"std 75.960740\n",
"min 1.000000\n",
"25% 21.000000\n",
"50% 27.000000\n",
"75% 34.000000\n",
"max 1664.000000\n",
"Name: max_spikes, dtype: float64"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[df['high K concentration'] == '8 mM', 'max_spikes'].describe()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "660e2af2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"count 353.000000\n",
"mean 23.844193\n",
"std 10.519791\n",
"min 0.000000\n",
"25% 18.000000\n",
"50% 24.000000\n",
"75% 31.000000\n",
"max 48.000000\n",
"Name: max_spikes, dtype: float64"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[df['high K concentration'] == '15 mM', 'max_spikes'].describe()"
]
},
{
"cell_type": "markdown",
"id": "8b2d1c2b",
"metadata": {},
"source": [
"## 8. Display the statistics of `max_spikes` when `high K concentration` is `8 mM`, and the maximum number of spikes is <= 100\n",
"\n",
"Does that change your conclusion?"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "eec287c7",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"count 473.000000\n",
"mean 27.503171\n",
"std 10.965493\n",
"min 1.000000\n",
"25% 21.000000\n",
"50% 27.000000\n",
"75% 34.000000\n",
"max 61.000000\n",
"Name: max_spikes, dtype: float64"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.loc[(df['high K concentration'] == '8 mM') & (df['max_spikes'] <= 100), 'max_spikes'].describe()"
]
},
{
"cell_type": "markdown",
"id": "6dbbf6c8",
"metadata": {},
"source": [
"## 9. Transform the `high K concentration` column into a numerical column\n",
"\n",
"a) Discard the last three characters of the columns (`' mM'`)\n",
"\n",
"b) Use `.astype(float)` to convert to floating point numbers\n",
"\n",
"c) Save the result in a column `K (mM)`"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "3a2bcc9c",
"metadata": {},
"outputs": [],
"source": [
"df['K (mM)'] = df['high K concentration'].str[:-3].astype(float)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "35061149",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>OP</th>\n",
" <th>filename</th>\n",
" <th>slice</th>\n",
" <th>cell_ch</th>\n",
" <th>cell_ID</th>\n",
" <th>day</th>\n",
" <th>treatment</th>\n",
" <th>hrs_incubation</th>\n",
" <th>repatch</th>\n",
" <th>hrs_after_OP</th>\n",
" <th>Rs</th>\n",
" <th>Rin</th>\n",
" <th>resting_potential</th>\n",
" <th>max_spikes</th>\n",
" <th>Rheobase</th>\n",
" <th>AP_heigth</th>\n",
" <th>TH</th>\n",
" <th>max_depol</th>\n",
" <th>max_repol</th>\n",
" <th>membra_time_constant_tau</th>\n",
" <th>capacitance</th>\n",
" <th>comments</th>\n",
" <th>rheo_ramp</th>\n",
" <th>AP_halfwidth</th>\n",
" <th>Rheobse_ramp</th>\n",
" <th>Unnamed: 27</th>\n",
" <th>rheos_ramp</th>\n",
" <th>comment</th>\n",
" <th></th>\n",
" <th>high K concentration</th>\n",
" <th>RMP_from_char</th>\n",
" <th>K (mM)</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>OP230420</td>\n",
" <td>23420003.abf</td>\n",
" <td>S1</td>\n",
" <td>1</td>\n",
" <td>23420S1c1</td>\n",
" <td>D1</td>\n",
" <td>TTX</td>\n",
" <td>0.0</td>\n",
" <td>no</td>\n",
" <td>10.416389</td>\n",
" <td>6.675643</td>\n",
" <td>39.025301</td>\n",
" <td>-74.285889</td>\n",
" <td>24</td>\n",
" <td>200.0</td>\n",
" <td>80.749512</td>\n",
" <td>-35.278320</td>\n",
" <td>336.181641</td>\n",
" <td>-60.791016</td>\n",
" <td>19.40</td>\n",
" <td>510.601767</td>\n",
" <td>0</td>\n",
" <td>753.380113</td>\n",
" <td>1.151009</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-61.828554</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>OP230420</td>\n",
" <td>23420003.abf</td>\n",
" <td>S1</td>\n",
" <td>3</td>\n",
" <td>23420S1c3</td>\n",
" <td>D1</td>\n",
" <td>TTX</td>\n",
" <td>0.0</td>\n",
" <td>no</td>\n",
" <td>10.416389</td>\n",
" <td>7.867174</td>\n",
" <td>48.728367</td>\n",
" <td>-69.573975</td>\n",
" <td>26</td>\n",
" <td>300.0</td>\n",
" <td>78.448486</td>\n",
" <td>-32.043457</td>\n",
" <td>350.097656</td>\n",
" <td>-67.138672</td>\n",
" <td>17.30</td>\n",
" <td>393.397918</td>\n",
" <td>1</td>\n",
" <td>585.102837</td>\n",
" <td>1.006321</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-60.460298</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>OP230420</td>\n",
" <td>23420003.abf</td>\n",
" <td>S1</td>\n",
" <td>6</td>\n",
" <td>23420S1c6</td>\n",
" <td>D1</td>\n",
" <td>TTX</td>\n",
" <td>0.0</td>\n",
" <td>no</td>\n",
" <td>10.416389</td>\n",
" <td>8.820134</td>\n",
" <td>35.971082</td>\n",
" <td>-54.956055</td>\n",
" <td>22</td>\n",
" <td>300.0</td>\n",
" <td>76.660156</td>\n",
" <td>-29.827881</td>\n",
" <td>270.629883</td>\n",
" <td>-52.246094</td>\n",
" <td>14.85</td>\n",
" <td>426.098774</td>\n",
" <td>3</td>\n",
" <td>173.915797</td>\n",
" <td>1.266335</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-59.615979</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>OP230420</td>\n",
" <td>23420003.abf</td>\n",
" <td>S1</td>\n",
" <td>7</td>\n",
" <td>23420S1c7</td>\n",
" <td>D1</td>\n",
" <td>TTX</td>\n",
" <td>0.0</td>\n",
" <td>yes</td>\n",
" <td>10.416389</td>\n",
" <td>7.269195</td>\n",
" <td>39.186101</td>\n",
" <td>-69.268799</td>\n",
" <td>24</td>\n",
" <td>300.0</td>\n",
" <td>75.030518</td>\n",
" <td>-29.699707</td>\n",
" <td>242.553711</td>\n",
" <td>-71.411133</td>\n",
" <td>17.15</td>\n",
" <td>478.273362</td>\n",
" <td>4</td>\n",
" <td>598.079936</td>\n",
" <td>0.994396</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-61.173839</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>OP230420</td>\n",
" <td>23420003.abf</td>\n",
" <td>S1</td>\n",
" <td>8</td>\n",
" <td>23420S1c8</td>\n",
" <td>D1</td>\n",
" <td>TTX</td>\n",
" <td>0.0</td>\n",
" <td>yes</td>\n",
" <td>10.416389</td>\n",
" <td>6.000400</td>\n",
" <td>31.599917</td>\n",
" <td>-70.550537</td>\n",
" <td>22</td>\n",
" <td>350.0</td>\n",
" <td>81.011963</td>\n",
" <td>-33.068848</td>\n",
" <td>309.448242</td>\n",
" <td>-61.401367</td>\n",
" <td>16.65</td>\n",
" <td>575.513924</td>\n",
" <td>5</td>\n",
" <td>786.927898</td>\n",
" <td>1.182830</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>8 mM</td>\n",
" <td>-60.956350</td>\n",
" <td>8.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" OP filename slice cell_ch cell_ID day treatment \\\n",
"0 OP230420 23420003.abf S1 1 23420S1c1 D1 TTX \n",
"1 OP230420 23420003.abf S1 3 23420S1c3 D1 TTX \n",
"2 OP230420 23420003.abf S1 6 23420S1c6 D1 TTX \n",
"3 OP230420 23420003.abf S1 7 23420S1c7 D1 TTX \n",
"4 OP230420 23420003.abf S1 8 23420S1c8 D1 TTX \n",
"\n",
" hrs_incubation repatch hrs_after_OP Rs Rin \\\n",
"0 0.0 no 10.416389 6.675643 39.025301 \n",
"1 0.0 no 10.416389 7.867174 48.728367 \n",
"2 0.0 no 10.416389 8.820134 35.971082 \n",
"3 0.0 yes 10.416389 7.269195 39.186101 \n",
"4 0.0 yes 10.416389 6.000400 31.599917 \n",
"\n",
" resting_potential max_spikes Rheobase AP_heigth TH max_depol \\\n",
"0 -74.285889 24 200.0 80.749512 -35.278320 336.181641 \n",
"1 -69.573975 26 300.0 78.448486 -32.043457 350.097656 \n",
"2 -54.956055 22 300.0 76.660156 -29.827881 270.629883 \n",
"3 -69.268799 24 300.0 75.030518 -29.699707 242.553711 \n",
"4 -70.550537 22 350.0 81.011963 -33.068848 309.448242 \n",
"\n",
" max_repol membra_time_constant_tau capacitance comments rheo_ramp \\\n",
"0 -60.791016 19.40 510.601767 0 753.380113 \n",
"1 -67.138672 17.30 393.397918 1 585.102837 \n",
"2 -52.246094 14.85 426.098774 3 173.915797 \n",
"3 -71.411133 17.15 478.273362 4 598.079936 \n",
"4 -61.401367 16.65 575.513924 5 786.927898 \n",
"\n",
" AP_halfwidth Rheobse_ramp Unnamed: 27 rheos_ramp comment \\\n",
"0 1.151009 NaN NaN NaN NaN NaN \n",
"1 1.006321 NaN NaN NaN NaN NaN \n",
"2 1.266335 NaN NaN NaN NaN NaN \n",
"3 0.994396 NaN NaN NaN NaN NaN \n",
"4 1.182830 NaN NaN NaN NaN NaN \n",
"\n",
" high K concentration RMP_from_char K (mM) \n",
"0 8 mM -61.828554 8.0 \n",
"1 8 mM -60.460298 8.0 \n",
"2 8 mM -59.615979 8.0 \n",
"3 8 mM -61.173839 8.0 \n",
"4 8 mM -60.956350 8.0 "
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ecc0cad1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}