Commit 0820e4c9 authored by rhaase's avatar rhaase

added slides and notebooks

parent b104896a
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
,Area,Mean,Circ.,AR,Round,Solidity
1,2610,96.920,0.773,1.289,0.776,1.000
2,2100,90.114,0.660,2.333,0.429,1.000
3,27,110.222,0.108,27.000,0.037,1.000
# ,Area,Mean,Circ.,AR,Round,Solidity
1.000000000000000000e+00,2.610000000000000000e+03,9.692000000000000171e+01,7.730000000000000204e-01,1.288999999999999924e+00,7.760000000000000231e-01,1.000000000000000000e+00
2.000000000000000000e+00,2.100000000000000000e+03,9.011400000000000432e+01,6.600000000000000311e-01,2.333000000000000185e+00,4.289999999999999925e-01,1.000000000000000000e+00
3.000000000000000000e+00,2.700000000000000000e+01,1.102219999999999942e+02,1.079999999999999988e-01,2.700000000000000000e+01,3.699999999999999817e-02,1.000000000000000000e+00
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello world\n"
]
}
],
"source": [
"print(\"Hello world\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Math in python"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Explanation"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"12\n"
]
}
],
"source": [
"a = 5\n",
"b = 7\n",
"\n",
"print(a + b)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Headline\n",
"Normal text\n",
"\n",
"* Bullet points"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Working with tables in pandas"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Load a csv file from disc and show it"
]
},
{
"cell_type": "code",
"execution_count": 1,
"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></th>\n",
" <th>Area</th>\n",
" <th>Mean</th>\n",
" <th>Circ.</th>\n",
" <th>AR</th>\n",
" <th>Round</th>\n",
" <th>Solidity</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>2610</td>\n",
" <td>96.920</td>\n",
" <td>0.773</td>\n",
" <td>1.289</td>\n",
" <td>0.776</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>2100</td>\n",
" <td>90.114</td>\n",
" <td>0.660</td>\n",
" <td>2.333</td>\n",
" <td>0.429</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>27</td>\n",
" <td>110.222</td>\n",
" <td>0.108</td>\n",
" <td>27.000</td>\n",
" <td>0.037</td>\n",
" <td>1.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Area Mean Circ. AR Round Solidity\n",
"0 1 2610 96.920 0.773 1.289 0.776 1.0\n",
"1 2 2100 90.114 0.660 2.333 0.429 1.0\n",
"2 3 27 110.222 0.108 27.000 0.037 1.0"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import pandas as pd\n",
"\n",
"data_frame = pd.read_csv(\"Measurements_ImageJ.csv\", delimiter=',')\n",
"\n",
"# show it\n",
"data_frame"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Take a column out of the table"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 0.776\n",
"1 0.429\n",
"2 0.037\n",
"Name: Round, dtype: float64"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data_frame[\"Round\"]"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0 96.920\n",
"1 90.114\n",
"2 110.222\n",
"Name: Mean, dtype: float64"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data_frame[\"Mean\"]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Determine the mean of a column"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"99.08533333333332"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import numpy as np\n",
"np.mean(data_frame[\"Mean\"])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Read out one particular cell of the table"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"1.2890000000000001"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data_frame[\"Mean\"][0]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Iterate with a for loop over all cells in a column"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"96.92\n",
"90.11399999999999\n",
"110.22200000000001\n"
]
}
],
"source": [
"for mean_intensity in data_frame[\"Mean\"]:\n",
" print(mean_intensity)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Make a new table from scratch"
]
},
{
"cell_type": "code",
"execution_count": 18,
"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>0</th>\n",
" <th>1</th>\n",
" <th>2</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>A</th>\n",
" <td>1</td>\n",
" <td>2</td>\n",
" <td>3</td>\n",
" </tr>\n",
" <tr>\n",
" <th>B</th>\n",
" <td>4</td>\n",
" <td>5</td>\n",
" <td>6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>C</th>\n",
" <td>7</td>\n",
" <td>8</td>\n",
" <td>9</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" 0 1 2\n",
"A 1 2 3\n",
"B 4 5 6\n",
"C 7 8 9"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"header = ['A', 'B', 'C']\n",
"\n",
"data = [\n",
" [1, 2, 3], # this will later be colum A\n",
" [4, 5, 6], # B\n",
" [7, 8, 9] # C\n",
"]\n",
"\n",
"# convert the data and header arrays in a pandas data frame\n",
"data_frame = pd.DataFrame(data, header)\n",
"\n",
"# show it\n",
"data_frame"
]
},
{
"cell_type": "code",
"execution_count": 19,
"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>A</th>\n",
" <th>B</th>\n",
" <th>C</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" <td>4</td>\n",
" <td>7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>5</td>\n",
" <td>8</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" <td>6</td>\n",
" <td>9</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B C\n",
"0 1 4 7\n",
"1 2 5 8\n",
"2 3 6 9"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# rotate/flip it\n",
"data_frame = data_frame.transpose()\n",
"\n",
"# show it\n",
"data_frame"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"# save a dataframe to a CSV\n",
"data_frame.to_csv(\"output.csv\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.8.3"
},
"toc": {
"base_numbering": 1,
"nav_menu": {},
"number_sections": false,
"sideBar": false,
"skip_h1_title": false,
"title_cell": "Table of Contents",
"title_sidebar": "Contents",
"toc_cell": false,
"toc_position": {},
"toc_section_display": false,
"toc_window_display": false
}
},
"nbformat": 4,
"nbformat_minor": 2
}
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment