Add source example files
This commit is contained in:
161
source/jupyter/02-intro-to-pandas.ipynb
Normal file
161
source/jupyter/02-intro-to-pandas.ipynb
Normal file
@ -0,0 +1,161 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"id": "e328e5fa-ee7e-4045-9164-624573b73562",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"0 1\n",
|
||||
"1 3\n",
|
||||
"2 7\n",
|
||||
"3 8\n",
|
||||
"dtype: int64\n",
|
||||
"7\n",
|
||||
"int64\n",
|
||||
"[1 3 7 8]\n",
|
||||
"None\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"s1 = pd.Series([1, 3, 7, 8])\n",
|
||||
"print(s1)\n",
|
||||
"print(s1[2])\n",
|
||||
"print(s1.dtype)\n",
|
||||
"print(s1.values)\n",
|
||||
"print(s1.name)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 4,
|
||||
"id": "4f15f4f9-2580-41c3-a26c-80152d739ab5",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
" 0 1\n",
|
||||
"0 Paul 1974\n",
|
||||
"1 Quentin 1991\n",
|
||||
"2 Aude 1987\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"dataframe = pd.DataFrame(data=[[\"Paul\", 1974], [\"Quentin\", 1991], [\"Aude\", 1987]])\n",
|
||||
"print(dataframe)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"id": "1f2c617f-3ee6-4254-ba1d-1c517e4be013",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"Alain\n",
|
||||
"Index(['U1', 'U2', 'U3', 'U4', 'U5', 'U6'], dtype='object')\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"s1 = pd.Series(data=[\"Alain\", \"Lucie\", \"Gilles\", \"André\", \"Zoé\", \"Paul\"], index=[\"U1\", \"U2\", \"U3\", \"U4\", \"U5\", \"U6\"])\n",
|
||||
"print(s1[\"U1\"]) # Affiche la valeur \"Alain\" en extrayant depuis l'index \"U1\"\n",
|
||||
"print(s1.index)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"id": "008357ca-4a95-48bb-a411-aaf2b6182ae2",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"0 1\n",
|
||||
"1 3\n",
|
||||
"2 2\n",
|
||||
"3 3\n",
|
||||
"dtype: int64\n",
|
||||
"0 False\n",
|
||||
"1 False\n",
|
||||
"2 True\n",
|
||||
"3 True\n",
|
||||
"dtype: bool\n",
|
||||
"False\n",
|
||||
"True\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import pandas as pd\n",
|
||||
"\n",
|
||||
"s1 = pd.Series([1, 3, 7, 8])\n",
|
||||
"print(s1 % 5)\n",
|
||||
"print(s1 * 2 - 7 > 4)\n",
|
||||
"print(8 in s1) # C'est faux car \"in\" cherche uniquement dans l'index (comme avec les dict)\n",
|
||||
"print(8 in s1.values) # C'est vrai car la valeur 8 est présente dans le tableau de valeurs"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"id": "b4cb5f27-485d-4d79-bf4b-a6dcbfc906b6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"False"
|
||||
]
|
||||
},
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"19 in {\"plop\": 19, \"plip\": 99}"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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.12.5"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
Reference in New Issue
Block a user