This commit is contained in:
Paul Corbalan 2023-08-21 17:12:19 +02:00
commit d57275d772
141 changed files with 108552 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

0
.Rhistory Normal file
View File

3
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,3 @@
{
"python.pythonPath": "C:\\Users\\Main-user\\anaconda3\\envs\\pyfinance\\python.exe"
}

View File

@ -0,0 +1,444 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Python Cours Accéléré - Exercices \n",
"\n",
"Cet exercice est facultatif, il permet de tester votre niveau Python. Les questions traitent au maximum le thème financier, mais ne vous attardez pas sur ces tâches, beaucoup dentre elles nont aucune signification et nont pas de sens. Si vous trouvez cela extrêmement difficile, vous n'êtes probablement pas encore prêt pour le reste de ce cours et n'avez pas assez d'expérience en programmation pour continuer. Je vous suggère de prendre un autre cours plus orienté vers les débutants complets, tels que [Formation complète Python](https://www.udemy.com/course/python-datascience/?referralCode=9DB381B321631A0703C2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercices\n",
"\n",
"Répondez aux questions ou effectuez les exercices en gras ci-dessous, utilisez la méthode spécifique décrite le cas échéant."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #1\n",
"\n",
"Soit un prix donné price = 300, utilisez python pour trouver la raciné carrée du prix."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"price = 300"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17.320508075688775"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17.320508075688775"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #2\n",
"\n",
"Soit la chaîne de caractères:\n",
"\n",
" stock_index = \"SP500\"\n",
" \n",
"Extraire '500' de la chaîne de caractères à l'aide de la méthode d'indexation."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"stock_index = \"SP500\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'500'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #3\n",
"\n",
"** Soient les variables:**\n",
"\n",
" stock_index = \"SP500\"\n",
" price = 300\n",
"\n",
"** Utilisez .format() pour afficher la phrase suivante: **\n",
"\n",
" Le SP500 est à 300 aujourd'hui."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"stock_index = \"SP500\"\n",
"price = 300"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Le SP500 est à 300 aujourd'hui\n"
]
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #4\n",
"\n",
"** Soit la variable d'un dictionnaire imbriqué avec les listes imbriquées suivantes: **\n",
"\n",
" stock_info = {'sp500':{'today':300,'yesterday': 250}, 'info':['Time',[24,7,365]]}\n",
" \n",
"** Utilisez l'indexation et les clés correspondantes pour extraire les éléments suivants:**\n",
"\n",
"* Le prix du SP500 d'hier (250)\n",
"* Le nombre 365 imbriqué à l'intérieur d'une liste imnbriquée au niveau de la clé 'info'."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"stock_info = {'sp500':{'today':300,'yesterday': 250}, 'info':['Time',[24,7,365]]}"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"250"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"365"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #5\n",
"\n",
"** Soient des chaînes de caractères données avec cette forme où la dernière valeur source est toujours séparée par 2 tirets -- **\n",
"\n",
" \"PRICE:345.324:SOURCE--QUANDL\"\n",
" \n",
"**Créer une fonction nommée source_finder() qui retourne la source. Par exemple, la chaîne de caractères ci-dessus passée en argument dans la fonction devrait retourner \"QUANDL\"**"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'QUANDL'"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source_finder(\"PRICE:345.324:SOURCE--QUANDL\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #6\n",
"\n",
"** Créer une fonction nommée price_finder() qui retourne True si le mot 'prix' est dans la chaîne de caractères. Votre fonction doit fonctionner même si 'Prix' commence par une majuscule ou suivi directement d'une ponctuation ('prix!') **"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"Quel est le prix?\")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"MEC, QUEL EST LE PRIX!!!\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"Le prix est 300\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #7\n",
"\n",
"** Créer une fonction nommée count_price() qui compte le nombre de fois que le mot \"prix\" apparaît dans la chaîne de caractères. Prendre en compte la majuscule et si le mot \"prix\" est proche d'une ponctuation. **"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"s = \"Wow quel bon prix, très très bon Prix! J'ai dit prix 3 fois.\""
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"count_price(s)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #8\n",
"\n",
"**Créer une fonction nommée avg_price qui prend en paramètre une liste de nombres (prix d'action) et en calcule la moyenne (somme de tous les nombres divisée par le nombre d'éléments de la liste). Cela doit retourner un décimal float. **"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4.0"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"avg_price([3,4,5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon Travail!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,507 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Python Cours Accéléré - Solutions\n",
"\n",
"Cet exercice est facultatif, il permet de tester votre niveau Python. Les questions traitent au maximum le thème financier, mais ne vous attardez pas sur ces tâches, beaucoup dentre elles nont aucune signification et nont pas de sens. Si vous trouvez cela extrêmement difficile, vous n'êtes probablement pas encore prêt pour le reste de ce cours et n'avez pas assez d'expérience en programmation pour continuer. Je vous suggère de prendre un autre cours plus orienté vers les débutants complets, tels que [Formation complète Python](https://www.udemy.com/course/python-datascience/?referralCode=9DB381B321631A0703C2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercices\n",
"\n",
"Répondez aux questions ou effectuez les exercices en gras ci-dessous, utilisez la méthode spécifique décrite le cas échéant."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #1\n",
"\n",
"Soit un prix donné price = 300, utilisez python pour trouver la raciné carrée du prix."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"price = 300"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17.320508075688775"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price**(0.5)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17.320508075688775"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import math\n",
"math.sqrt(price)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #2\n",
"\n",
"Soit la chaîne de caractères:\n",
"\n",
" stock_index = \"SP500\"\n",
" \n",
"Extraire '500' de la chaîne de caractères à l'aide de la méthode d'indexation."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"stock_index = \"SP500\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'500'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stock_index[2:]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #3\n",
"\n",
"** Soient les variables:**\n",
"\n",
" stock_index = \"SP500\"\n",
" price = 300\n",
"\n",
"** Utilisez .format() pour afficher la phrase suivante: **\n",
"\n",
" Le SP500 est à 300 aujourd'hui."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"stock_index = \"SP500\"\n",
"price = 300"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Le SP500 est à 300 aujourd'hui\n"
]
}
],
"source": [
"print(\"Le {} est à {} aujourd'hui\".format(stock_index,price))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #4\n",
"\n",
"** Soit la variable d'un dictionnaire imbriqué avec les listes imbriquées suivantes: **\n",
"\n",
" stock_info = {'sp500':{'today':300,'yesterday': 250}, 'info':['Time',[24,7,365]]}\n",
" \n",
"** Utilisez l'indexation et les clés correspondantes pour extraire les éléments suivants:**\n",
"\n",
"* Le prix du SP500 d'hier (250)\n",
"* Le nombre 365 imbriqué à l'intérieur d'une liste imnbriquée au niveau de la clé 'info'."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"stock_info = {'sp500':{'today':300,'yesterday': 250}, 'info':['Time',[24,7,365]]}"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['sp500', 'info'])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stock_info.keys()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"250"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stock_info['sp500']['yesterday']"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"365"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stock_info['info'][1][2]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #5\n",
"\n",
"** Soient des chaînes de caractères données avec cette forme où la dernière valeur source est toujours séparée par 2 tirets -- **\n",
"\n",
" \"PRICE:345.324:SOURCE--QUANDL\"\n",
" \n",
"**Créer une fonction nommée source_finder() qui retourne la source. Par exemple, la chaîne de caractères ci-dessus passée en argument dans la fonction devrait retourner \"QUANDL\"**"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"def source_finder(s):\n",
" return s.split('--')[-1]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'QUANDL'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source_finder(\"PRICE:345.324:SOURCE--QUANDL\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #6\n",
"\n",
"** Créer une fonction nommée price_finder() qui retourne True si le mot 'prix' est dans la chaîne de caractères. Votre fonction doit fonctionner même si 'Prix' commence par une majuscule ou suivi directement d'une ponctuation ('prix!') **"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"def price_finder(s):\n",
" return 'prix' in s.lower()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"Quel est le prix?\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"MEC, QUEL EST LE PRIX!!!\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"Le prix est 300\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #7\n",
"\n",
"** Créer une fonction nommée count_price() qui compte le nombre de fois que le mot \"prix\" apparaît dans la chaîne de caractères. Prendre en compte la majuscule et si le mot \"prix\" est proche d'une ponctuation. **"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"def count_price(s):\n",
" count = 0\n",
" \n",
" for word in s.lower().split():\n",
" # Besoin d'utiliser in, == ne fonctionne pas avec la ponctuation\n",
" if 'prix' in word:\n",
" count = count + 1\n",
" \n",
" # Attention à l'indentation!\n",
" return count"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"def count_price(s):\n",
" return s.lower().count('prix')"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"s = \"Wow quel bon prix, très très bon Prix! J'ai dit prix 3 fois.\""
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"count_price(s)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #8\n",
"\n",
"**Créer une fonction nommée avg_price qui prend en paramètre une liste de nombres (prix d'action) et en calcule la moyenne (somme de tous les nombres divisée par le nombre d'éléments de la liste). Cela doit retourner un décimal float. **"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"def avg_price(stocks):\n",
" return sum(stocks)/len(stocks)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4.0"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"avg_price([3,4,5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon Travail!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,507 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Python Cours Accéléré - Solutions\n",
"\n",
"Cet exercice est facultatif, il permet de tester votre niveau Python. Les questions traitent au maximum le thème financier, mais ne vous attardez pas sur ces tâches, beaucoup dentre elles nont aucune signification et nont pas de sens. Si vous trouvez cela extrêmement difficile, vous n'êtes probablement pas encore prêt pour le reste de ce cours et n'avez pas assez d'expérience en programmation pour continuer. Je vous suggère de prendre un autre cours plus orienté vers les débutants complets, tels que [Formation complète Python](https://www.udemy.com/course/python-datascience/?referralCode=9DB381B321631A0703C2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercices\n",
"\n",
"Répondez aux questions ou effectuez les exercices en gras ci-dessous, utilisez la méthode spécifique décrite le cas échéant."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #1\n",
"\n",
"Soit un prix donné price = 300, utilisez python pour trouver la raciné carrée du prix."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"price = 300"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17.320508075688775"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price**(0.5)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17.320508075688775"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"import math\n",
"math.sqrt(price)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #2\n",
"\n",
"Soit la chaîne de caractères :\n",
"\n",
" stock_index = \"SP500\"\n",
" \n",
"Extraire '500' de la chaîne de caractères à l'aide de la méthode d'indexation."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"stock_index = \"SP500\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'500'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stock_index[2:]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #3\n",
"\n",
"**Soient les variables :**\n",
"\n",
" stock_index = \"SP500\"\n",
" price = 300\n",
"\n",
"**Utilisez .format() pour afficher la phrase suivante :**\n",
"\n",
" Le SP500 est à 300 aujourd'hui."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"stock_index = \"SP500\"\n",
"price = 300"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Le SP500 est à 300 aujourd'hui\n"
]
}
],
"source": [
"print(\"Le {} est à {} aujourd'hui\".format(stock_index,price))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #4\n",
"\n",
"**Soit la variable d'un dictionnaire imbriqué avec les listes imbriquées suivantes :**\n",
"\n",
" stock_info = {'sp500':{'today':300,'yesterday': 250}, 'info':['Time',[24,7,365]]}\n",
" \n",
"**Utilisez l'indexation et les clés correspondantes pour extraire les éléments suivants :**\n",
"\n",
"* Le prix du SP500 d'hier (250)\n",
"* Le nombre 365 imbriqué à l'intérieur d'une liste imnbriquée au niveau de la clé 'info'."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"stock_info = {'sp500':{'today':300,'yesterday': 250}, 'info':['Time',[24,7,365]]}"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dict_keys(['sp500', 'info'])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stock_info.keys()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"250"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stock_info['sp500']['yesterday']"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"365"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"stock_info['info'][1][2]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #5\n",
"\n",
"**Soient des chaînes de caractères données avec cette forme où la dernière valeur source est toujours séparée par 2 tirets --**\n",
"\n",
" \"PRICE:345.324:SOURCE--QUANDL\"\n",
" \n",
"**Créer une fonction nommée source_finder() qui retourne la source. Par exemple, la chaîne de caractères ci-dessus passée en argument dans la fonction devrait retourner \"QUANDL\"**"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"def source_finder(s):\n",
" return s.split('--')[-1]"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'QUANDL'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source_finder(\"PRICE:345.324:SOURCE--QUANDL\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #6\n",
"\n",
"**Créer une fonction nommée price_finder() qui retourne True si le mot 'prix' est dans la chaîne de caractères. Votre fonction doit fonctionner même si 'Prix' commence par une majuscule ou suivi directement d'une ponctuation ('prix!')**"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"def price_finder(s):\n",
" return 'prix' in s.lower()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"Quel est le prix?\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"MEC, QUEL EST LE PRIX!!!\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"Le prix est 300\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #7\n",
"\n",
"**Créer une fonction nommée count_price() qui compte le nombre de fois que le mot \"prix\" apparaît dans la chaîne de caractères. Prendre en compte la majuscule et si le mot \"prix\" est proche d'une ponctuation.**"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"def count_price(s):\n",
" count = 0\n",
" \n",
" for word in s.lower().split():\n",
" # Besoin d'utiliser in, == ne fonctionne pas avec la ponctuation\n",
" if 'prix' in word:\n",
" count = count + 1\n",
" \n",
" # Attention à l'indentation!\n",
" return count"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"def count_price(s):\n",
" return s.lower().count('prix')"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"s = \"Wow quel bon prix, très très bon Prix! J'ai dit prix 3 fois.\""
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"count_price(s)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #8\n",
"\n",
"**Créer une fonction nommée avg_price qui prend en paramètre une liste de nombres (prix d'action) et en calcule la moyenne (somme de tous les nombres divisée par le nombre d'éléments de la liste). Cela doit retourner un décimal float.**"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"def avg_price(stocks):\n",
" return sum(stocks)/len(stocks)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4.0"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"avg_price([3,4,5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon Travail!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,444 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Python Cours Accéléré - Exercices\n",
"\n",
"Cet exercice est facultatif, il permet de tester votre niveau Python. Les questions traitent au maximum le thème financier, mais ne vous attardez pas sur ces tâches, beaucoup dentre elles nont aucune signification et nont pas de sens. Si vous trouvez cela extrêmement difficile, vous n'êtes probablement pas encore prêt pour le reste de ce cours et n'avez pas assez d'expérience en programmation pour continuer. Je vous suggère de prendre un autre cours plus orienté vers les débutants complets, tels que [Formation complète Python](https://www.udemy.com/course/python-datascience/?referralCode=9DB381B321631A0703C2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exercices\n",
"\n",
"Répondez aux questions ou effectuez les exercices en gras ci-dessous, utilisez la méthode spécifique décrite le cas échéant."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #1\n",
"\n",
"Soit un prix donné price = 300, utilisez python pour trouver la raciné carrée du prix."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"price = 300"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17.320508075688775"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"17.320508075688775"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #2\n",
"\n",
"Soit la chaîne de caractères :\n",
"\n",
" stock_index = \"SP500\"\n",
" \n",
"Extraire '500' de la chaîne de caractères à l'aide de la méthode d'indexation."
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"stock_index = \"SP500\""
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'500'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #3\n",
"\n",
"**Soient les variables :**\n",
"\n",
" stock_index = \"SP500\"\n",
" price = 300\n",
"\n",
"**Utilisez .format() pour afficher la phrase suivante :**\n",
"\n",
" Le SP500 est à 300 aujourd'hui."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"stock_index = \"SP500\"\n",
"price = 300"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Le SP500 est à 300 aujourd'hui\n"
]
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #4\n",
"\n",
"**Soit la variable d'un dictionnaire imbriqué avec les listes imbriquées suivantes :**\n",
"\n",
" stock_info = {'sp500':{'today':300,'yesterday': 250}, 'info':['Time',[24,7,365]]}\n",
" \n",
"**Utilisez l'indexation et les clés correspondantes pour extraire les éléments suivants :**\n",
"\n",
"* Le prix du SP500 d'hier (250)\n",
"* Le nombre 365 imbriqué à l'intérieur d'une liste imnbriquée au niveau de la clé 'info'."
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"stock_info = {'sp500':{'today':300,'yesterday': 250}, 'info':['Time',[24,7,365]]}"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"250"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"365"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #5\n",
"\n",
"**Soient des chaînes de caractères données avec cette forme où la dernière valeur source est toujours séparée par 2 tirets --**\n",
"\n",
" \"PRICE:345.324:SOURCE--QUANDL\"\n",
" \n",
"**Créer une fonction nommée source_finder() qui retourne la source. Par exemple, la chaîne de caractères ci-dessus passée en argument dans la fonction devrait retourner \"QUANDL\"**"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'QUANDL'"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"source_finder(\"PRICE:345.324:SOURCE--QUANDL\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #6\n",
"\n",
"**Créer une fonction nommée price_finder() qui retourne True si le mot 'prix' est dans la chaîne de caractères. Votre fonction doit fonctionner même si 'Prix' commence par une majuscule ou suivi directement d'une ponctuation ('prix!')**"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"Quel est le prix?\")"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"MEC, QUEL EST LE PRIX!!!\")"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"price_finder(\"Le prix est 300\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #7\n",
"\n",
"**Créer une fonction nommée count_price() qui compte le nombre de fois que le mot \"prix\" apparaît dans la chaîne de caractères. Prendre en compte la majuscule et si le mot \"prix\" est proche d'une ponctuation.**"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [],
"source": [
"s = \"Wow quel bon prix, très très bon Prix! J'ai dit prix 3 fois.\""
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"count_price(s)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exercice #8\n",
"\n",
"**Créer une fonction nommée avg_price qui prend en paramètre une liste de nombres (prix d'action) et en calcule la moyenne (somme de tous les nombres divisée par le nombre d'éléments de la liste). Cela doit retourner un décimal float.**"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4.0"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"avg_price([3,4,5])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon Travail!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,973 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>\n",
"___\n",
"<center>*Copyright Pierian Data 2017*</center>\n",
"<center>*For more information, visit us at www.pieriandata.com*</center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# NumPy \n",
"\n",
"NumPy (or Numpy) is a Linear Algebra Library for Python, the reason it is so important for Finance with Python is that almost all of the libraries in the PyData Ecosystem rely on NumPy as one of their main building blocks. Plus we will use it to generate data for our analysis examples later on!\n",
"\n",
"Numpy is also incredibly fast, as it has bindings to C libraries. For more info on why you would want to use Arrays instead of lists, check out this great [StackOverflow post](http://stackoverflow.com/questions/993984/why-numpy-instead-of-python-lists).\n",
"\n",
"We will only learn the basics of NumPy, to get started we need to install it!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Installation Instructions\n",
"\n",
"### NumPy is already included in your environment! You are good to go if you are using pyfinance env!\n",
"\n",
"_____\n",
"##### For those not using the provided environment:\n",
"\n",
"**It is highly recommended you install Python using the Anaconda distribution to make sure all underlying dependencies (such as Linear Algebra libraries) all sync up with the use of a conda install. If you have Anaconda, install NumPy by going to your terminal or command prompt and typing:**\n",
" \n",
" conda install numpy\n",
" \n",
"**If you do not have Anaconda and can not install it, please refer to [Numpy's official documentation on various installation instructions.](http://docs.scipy.org/doc/numpy-1.10.1/user/install.html)**\n",
"\n",
"_____"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using NumPy\n",
"\n",
"Once you've installed NumPy you can import it as a library:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Numpy has many built-in functions and capabilities. We won't cover them all but instead we will focus on some of the most important aspects of Numpy: vectors,arrays,matrices, and number generation. Let's start by discussing arrays.\n",
"\n",
"# Numpy Arrays\n",
"\n",
"NumPy arrays are the main way we will use Numpy throughout the course. Numpy arrays essentially come in two flavors: vectors and matrices. Vectors are strictly 1-d arrays and matrices are 2-d (but you should note a matrix can still have only one row or one column).\n",
"\n",
"Let's begin our introduction by exploring how to create NumPy arrays.\n",
"\n",
"## Creating NumPy Arrays\n",
"\n",
"### From a Python List\n",
"\n",
"We can create an array by directly converting a list or list of lists:"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3]"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_list = [1,2,3]\n",
"my_list"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2, 3])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.array(my_list)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[1, 2, 3], [4, 5, 6], [7, 8, 9]]"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_matrix = [[1,2,3],[4,5,6],[7,8,9]]\n",
"my_matrix"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1, 2, 3],\n",
" [4, 5, 6],\n",
" [7, 8, 9]])"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.array(my_matrix)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Built-in Methods\n",
"\n",
"There are lots of built-in ways to generate Arrays"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### arange\n",
"\n",
"Return evenly spaced values within a given interval."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.arange(0,10)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 2, 4, 6, 8, 10])"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.arange(0,11,2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### zeros and ones\n",
"\n",
"Generate arrays of zeros or ones"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0., 0., 0.])"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.zeros(3)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0.]])"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.zeros((5,5))"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1., 1., 1.])"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.ones(3)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1., 1., 1.],\n",
" [ 1., 1., 1.],\n",
" [ 1., 1., 1.]])"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.ones((3,3))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### linspace\n",
"Return evenly spaced numbers over a specified interval."
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0., 5., 10.])"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.linspace(0,10,3)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0. , 0.20408163, 0.40816327, 0.6122449 ,\n",
" 0.81632653, 1.02040816, 1.2244898 , 1.42857143,\n",
" 1.63265306, 1.83673469, 2.04081633, 2.24489796,\n",
" 2.44897959, 2.65306122, 2.85714286, 3.06122449,\n",
" 3.26530612, 3.46938776, 3.67346939, 3.87755102,\n",
" 4.08163265, 4.28571429, 4.48979592, 4.69387755,\n",
" 4.89795918, 5.10204082, 5.30612245, 5.51020408,\n",
" 5.71428571, 5.91836735, 6.12244898, 6.32653061,\n",
" 6.53061224, 6.73469388, 6.93877551, 7.14285714,\n",
" 7.34693878, 7.55102041, 7.75510204, 7.95918367,\n",
" 8.16326531, 8.36734694, 8.57142857, 8.7755102 ,\n",
" 8.97959184, 9.18367347, 9.3877551 , 9.59183673,\n",
" 9.79591837, 10. ])"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.linspace(0,10,50)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## eye\n",
"\n",
"Creates an identity matrix"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1., 0., 0., 0.],\n",
" [ 0., 1., 0., 0.],\n",
" [ 0., 0., 1., 0.],\n",
" [ 0., 0., 0., 1.]])"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.eye(4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Random \n",
"\n",
"Numpy also has lots of ways to create random number arrays:\n",
"\n",
"### rand\n",
"Create an array of the given shape and populate it with\n",
"random samples from a uniform distribution\n",
"over ``[0, 1)``."
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.11570539, 0.35279769])"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.rand(2)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0.66660768, 0.87589888, 0.12421056, 0.65074126, 0.60260888],\n",
" [ 0.70027668, 0.85572434, 0.8464595 , 0.2735416 , 0.10955384],\n",
" [ 0.0670566 , 0.83267738, 0.9082729 , 0.58249129, 0.12305748],\n",
" [ 0.27948423, 0.66422017, 0.95639833, 0.34238788, 0.9578872 ],\n",
" [ 0.72155386, 0.3035422 , 0.85249683, 0.30414307, 0.79718816]])"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.rand(5,5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### randn\n",
"\n",
"Return a sample (or samples) from the \"standard normal\" distribution. Unlike rand which is uniform:"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([-0.27954018, 0.90078368])"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.randn(2)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0.70154515, 0.22441999, 1.33563186, 0.82872577, -0.28247509],\n",
" [ 0.64489788, 0.61815094, -0.81693168, -0.30102424, -0.29030574],\n",
" [ 0.8695976 , 0.413755 , 2.20047208, 0.17955692, -0.82159344],\n",
" [ 0.59264235, 1.29869894, -1.18870241, 0.11590888, -0.09181687],\n",
" [-0.96924265, -1.62888685, -2.05787102, -0.29705576, 0.68915542]])"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.randn(5,5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### randint\n",
"Return random integers from `low` (inclusive) to `high` (exclusive)."
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"44"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.randint(1,100)"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([13, 64, 27, 63, 46, 68, 92, 10, 58, 24])"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.randint(1,100,10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Array Attributes and Methods\n",
"\n",
"Let's discuss some useful attributes and methods or an array:"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"arr = np.arange(25)\n",
"ranarr = np.random.randint(0,50,10)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n",
" 17, 18, 19, 20, 21, 22, 23, 24])"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 12, 41, 17, 49, 2, 46, 3, 19, 39])"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reshape\n",
"Returns an array containing the same data with a new shape."
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0, 1, 2, 3, 4],\n",
" [ 5, 6, 7, 8, 9],\n",
" [10, 11, 12, 13, 14],\n",
" [15, 16, 17, 18, 19],\n",
" [20, 21, 22, 23, 24]])"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr.reshape(5,5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### max,min,argmax,argmin\n",
"\n",
"These are useful methods for finding max or min values. Or to find their index locations using argmin or argmax"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 12, 41, 17, 49, 2, 46, 3, 19, 39])"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"49"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr.max()"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr.argmax()"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr.min()"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr.argmin()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Shape\n",
"\n",
"Shape is an attribute that arrays have (not a method):"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(25,)"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Vector\n",
"arr.shape"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n",
" 17, 18, 19, 20, 21, 22, 23, 24]])"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Notice the two sets of brackets\n",
"arr.reshape(1,25)"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1, 25)"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr.reshape(1,25).shape"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0],\n",
" [ 1],\n",
" [ 2],\n",
" [ 3],\n",
" [ 4],\n",
" [ 5],\n",
" [ 6],\n",
" [ 7],\n",
" [ 8],\n",
" [ 9],\n",
" [10],\n",
" [11],\n",
" [12],\n",
" [13],\n",
" [14],\n",
" [15],\n",
" [16],\n",
" [17],\n",
" [18],\n",
" [19],\n",
" [20],\n",
" [21],\n",
" [22],\n",
" [23],\n",
" [24]])"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr.reshape(25,1)"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(25, 1)"
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr.reshape(25,1).shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### dtype\n",
"\n",
"You can also grab the data type of the object in the array:"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dtype('int64')"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr.dtype"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Great Job!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,329 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Opérations NumPy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Arithmétique\n",
"\n",
"Vous pouvez facilement effectuer un tableau avec l'arithmétique tableau, ou scalaire avec l'arithmétique tableau. Voyons quelques exemples :"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"arr = np.arange(0,10)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr + arr"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr * arr"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr - arr"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/marci/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:1: RuntimeWarning: invalid value encountered in true_divide\n",
" if __name__ == '__main__':\n"
]
},
{
"data": {
"text/plain": [
"array([ nan, 1., 1., 1., 1., 1., 1., 1., 1., 1.])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Avertissement en cas de division par zéro, mais pas une erreur !\n",
"# Seulement remplacé par nan\n",
"arr/arr"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/marci/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:1: RuntimeWarning: divide by zero encountered in true_divide\n",
" if __name__ == '__main__':\n"
]
},
{
"data": {
"text/plain": [
"array([ inf, 1. , 0.5 , 0.33333333, 0.25 ,\n",
" 0.2 , 0.16666667, 0.14285714, 0.125 , 0.11111111])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Avertissement aussi, mais pas une erreur, remplacé par l'infini\n",
"1/arr"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 1, 8, 27, 64, 125, 216, 343, 512, 729])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr**3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fonctions universelles de tableau\n",
"\n",
"Numpy vient avec beaucoup de [fonctions universelles de tableau](http://docs.scipy.org/doc/numpy/reference/ufuncs.html), qui sont essentiellement juste des opérations mathématiques que vous pouvez utiliser pour effectuer l'opération à travers le tableau. En voici quelques unes :"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0. , 1. , 1.41421356, 1.73205081, 2. ,\n",
" 2.23606798, 2.44948974, 2.64575131, 2.82842712, 3. ])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Prendre la racine carrée\n",
"np.sqrt(arr)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1.00000000e+00, 2.71828183e+00, 7.38905610e+00,\n",
" 2.00855369e+01, 5.45981500e+01, 1.48413159e+02,\n",
" 4.03428793e+02, 1.09663316e+03, 2.98095799e+03,\n",
" 8.10308393e+03])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Calcul exponentiel (e^)\n",
"np.exp(arr)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.max(arr) # comme arr.max()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0. , 0.84147098, 0.90929743, 0.14112001, -0.7568025 ,\n",
" -0.95892427, -0.2794155 , 0.6569866 , 0.98935825, 0.41211849])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.sin(arr)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/marci/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:1: RuntimeWarning: divide by zero encountered in log\n",
" if __name__ == '__main__':\n"
]
},
{
"data": {
"text/plain": [
"array([ -inf, 0. , 0.69314718, 1.09861229, 1.38629436,\n",
" 1.60943791, 1.79175947, 1.94591015, 2.07944154, 2.19722458])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.log(arr)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!\n",
"\n",
"C'est tout ce que nous avons besoin de savoir pour l'instant !"
]
}
],
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,646 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>\n",
"___\n",
"<center>*Copyright Pierian Data 2017*</center>\n",
"<center>*For more information, visit us at www.pieriandata.com*</center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# NumPy Indexing and Selection\n",
"\n",
"In this lecture we will discuss how to select elements or groups of elements from an array."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"#Creating sample array\n",
"arr = np.arange(0,11)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Show\n",
"arr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bracket Indexing and Selection\n",
"The simplest way to pick one or some elements of an array looks very similar to python lists:"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Get a value at an index\n",
"arr[8]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2, 3, 4])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Get values in a range\n",
"arr[1:5]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Get values in a range\n",
"arr[0:5]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Broadcasting\n",
"\n",
"Numpy arrays differ from a normal Python list because of their ability to broadcast:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([100, 100, 100, 100, 100, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Setting a value with index range (Broadcasting)\n",
"arr[0:5]=100\n",
"\n",
"#Show\n",
"arr"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Reset array, we'll see why I had to reset in a moment\n",
"arr = np.arange(0,11)\n",
"\n",
"#Show\n",
"arr"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4, 5])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Important notes on Slices\n",
"slice_of_arr = arr[0:6]\n",
"\n",
"#Show slice\n",
"slice_of_arr"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([99, 99, 99, 99, 99, 99])"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Change Slice\n",
"slice_of_arr[:]=99\n",
"\n",
"#Show Slice again\n",
"slice_of_arr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now note the changes also occur in our original array!"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([99, 99, 99, 99, 99, 99, 6, 7, 8, 9, 10])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Data is not copied, it's a view of the original array! This avoids memory problems!"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([99, 99, 99, 99, 99, 99, 6, 7, 8, 9, 10])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#To get a copy, need to be explicit\n",
"arr_copy = arr.copy()\n",
"\n",
"arr_copy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Indexing a 2D array (matrices)\n",
"\n",
"The general format is **arr_2d[row][col]** or **arr_2d[row,col]**. I recommend usually using the comma notation for clarity."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 5, 10, 15],\n",
" [20, 25, 30],\n",
" [35, 40, 45]])"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr_2d = np.array(([5,10,15],[20,25,30],[35,40,45]))\n",
"\n",
"#Show\n",
"arr_2d"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([20, 25, 30])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Indexing row\n",
"arr_2d[1]\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Format is arr_2d[row][col] or arr_2d[row,col]\n",
"\n",
"# Getting individual element value\n",
"arr_2d[1][0]"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Getting individual element value\n",
"arr_2d[1,0]"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[10, 15],\n",
" [25, 30]])"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# 2D array slicing\n",
"\n",
"#Shape (2,2) from top right corner\n",
"arr_2d[:2,1:]"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([35, 40, 45])"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Shape bottom row\n",
"arr_2d[2]"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([35, 40, 45])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#Shape bottom row\n",
"arr_2d[2,:]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## More Indexing Help\n",
"Indexing a 2d matrix can be a bit confusing at first, especially when you start to add in step size. Try google image searching NumPy indexing to fins useful images, like this one:\n",
"\n",
"<img src= 'http://memory.osu.edu/classes/python/_images/numpy_indexing.png' width=500/>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Conditional Selection\n",
"\n",
"This is a very fundamental concept that will directly translate to pandas later on, make sure you understand this part!\n",
"\n",
"Let's briefly go over how to use brackets for selection based off of comparison operators."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr = np.arange(1,11)\n",
"arr"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([False, False, False, False, True, True, True, True, True, True], dtype=bool)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr > 4"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"bool_arr = arr>4"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([False, False, False, False, True, True, True, True, True, True], dtype=bool)"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bool_arr"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr[bool_arr]"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 3, 4, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr[arr>2]"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 3, 4, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = 2\n",
"arr[arr>x]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Great Job!\n"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,817 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>\n",
"___\n",
"<center>*Copyright Pierian Data 2017*</center>\n",
"<center>*For more information, visit us at www.pieriandata.com*</center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# NumPy Exercises\n",
"Now that we've learned about NumPy let's test your knowledge. We'll start off with a few simple tasks and then you'll be asked some more complicated questions.\n",
"\n",
"** IMPORTANT NOTE! Make sure you don't run the cells directly above the example output shown, otherwise you will end up writing over the example output! **"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Import NumPy as np"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create an array of 10 zeros "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create an array of 10 ones"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create an array of 10 fives"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create an array of the integers from 10 to 50"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n",
" 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,\n",
" 44, 45, 46, 47, 48, 49, 50])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create an array of all the even integers from 10 to 50"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,\n",
" 44, 46, 48, 50])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create a 3x3 matrix with values ranging from 0 to 8"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0, 1, 2],\n",
" [3, 4, 5],\n",
" [6, 7, 8]])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create a 3x3 identity matrix"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1., 0., 0.],\n",
" [ 0., 1., 0.],\n",
" [ 0., 0., 1.]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Use NumPy to generate a random number between 0 and 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.42829726])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Use NumPy to generate an array of 25 random numbers sampled from a standard normal distribution"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1.32031013, 1.6798602 , -0.42985892, -1.53116655, 0.85753232,\n",
" 0.87339938, 0.35668636, -1.47491157, 0.15349697, 0.99530727,\n",
" -0.94865451, -1.69174783, 1.57525349, -0.70615234, 0.10991879,\n",
" -0.49478947, 1.08279872, 0.76488333, -2.3039931 , 0.35401124,\n",
" -0.45454399, -0.64754649, -0.29391671, 0.02339861, 0.38272124])"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create the following matrix:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ],\n",
" [ 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2 ],\n",
" [ 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3 ],\n",
" [ 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4 ],\n",
" [ 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5 ],\n",
" [ 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6 ],\n",
" [ 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7 ],\n",
" [ 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8 ],\n",
" [ 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9 ],\n",
" [ 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1. ]])"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Create an array of 20 linearly spaced points between 0 and 1:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0. , 0.05263158, 0.10526316, 0.15789474, 0.21052632,\n",
" 0.26315789, 0.31578947, 0.36842105, 0.42105263, 0.47368421,\n",
" 0.52631579, 0.57894737, 0.63157895, 0.68421053, 0.73684211,\n",
" 0.78947368, 0.84210526, 0.89473684, 0.94736842, 1. ])"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Numpy Indexing and Selection\n",
"\n",
"Now you will be given a few matrices, and be asked to replicate the resulting matrix outputs:"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1, 2, 3, 4, 5],\n",
" [ 6, 7, 8, 9, 10],\n",
" [11, 12, 13, 14, 15],\n",
" [16, 17, 18, 19, 20],\n",
" [21, 22, 23, 24, 25]])"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# HERE IS THE GIVEN MATRIX CALLED MAT\n",
"# USE IT FOR THE FOLLOWING TASKS\n",
"mat = np.arange(1,26).reshape(5,5)\n",
"mat"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n",
"# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n",
"# BE ABLE TO SEE THE OUTPUT ANY MORE"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[12, 13, 14, 15],\n",
" [17, 18, 19, 20],\n",
" [22, 23, 24, 25]])"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n",
"# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n",
"# BE ABLE TO SEE THE OUTPUT ANY MORE"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n",
"# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n",
"# BE ABLE TO SEE THE OUTPUT ANY MORE"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 2],\n",
" [ 7],\n",
" [12]])"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n",
"# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n",
"# BE ABLE TO SEE THE OUTPUT ANY MORE"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([21, 22, 23, 24, 25])"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# WRITE CODE HERE THAT REPRODUCES THE OUTPUT OF THE CELL BELOW\n",
"# BE CAREFUL NOT TO RUN THE CELL BELOW, OTHERWISE YOU WON'T\n",
"# BE ABLE TO SEE THE OUTPUT ANY MORE"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[16, 17, 18, 19, 20],\n",
" [21, 22, 23, 24, 25]])"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Now do the following"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Get the sum of all the values in mat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"325"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Get the standard deviation of the values in mat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7.2111025509279782"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Get the sum of all the columns in mat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE HERE"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([55, 60, 65, 70, 75])"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Bonus Question\n",
"\n",
"We worked a lot with random data with numpy, but is there a way we can insure that we always get the same random numbers? [Click Here for a Hint](https://www.google.com/search?q=numpy+random+seed&rlz=1C1CHBF_enUS747US747&oq=numpy+random+seed&aqs=chrome..69i57j69i60j0l4.2087j0j7&sourceid=chrome&ie=UTF-8)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Great Job!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,800 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercices NumPy\n",
"Maintenant que nous avons découvert NumPy, testons vos connaissances. Nous commencerons par quelques tâches simples, puis des questions plus complexes.\n",
"\n",
"** REMARQUE IMPORTANTE : Veillez à ne pas exécuter les cellules directement au-dessus de la sortie de résultat attendu, sinon vous risquez de finir par écrire par dessus ! **"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Import NumPy as np"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 10 zéros "
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 10 uns"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 10 cinq"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau d'entiers de 10 à 50"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n",
" 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,\n",
" 44, 45, 46, 47, 48, 49, 50])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de tous les entiers pairs entre 10 et 50"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,\n",
" 44, 46, 48, 50])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer une matrice 3x3 avec les valeurs de 0 à 8"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0, 1, 2],\n",
" [3, 4, 5],\n",
" [6, 7, 8]])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer une matrice identité 3x3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1., 0., 0.],\n",
" [ 0., 1., 0.],\n",
" [ 0., 0., 1.]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Utiliser NumPy pour générer un nombre aléatoire entre 0 et 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.42829726])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Utiliser NumPy pour générer un tableau de 25 nombres aléatoires échantillonnés à partir d'une distribution normale standard"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1.32031013, 1.6798602 , -0.42985892, -1.53116655, 0.85753232,\n",
" 0.87339938, 0.35668636, -1.47491157, 0.15349697, 0.99530727,\n",
" -0.94865451, -1.69174783, 1.57525349, -0.70615234, 0.10991879,\n",
" -0.49478947, 1.08279872, 0.76488333, -2.3039931 , 0.35401124,\n",
" -0.45454399, -0.64754649, -0.29391671, 0.02339861, 0.38272124])"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer la matrice suivante:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ],\n",
" [ 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2 ],\n",
" [ 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3 ],\n",
" [ 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4 ],\n",
" [ 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5 ],\n",
" [ 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6 ],\n",
" [ 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7 ],\n",
" [ 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8 ],\n",
" [ 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9 ],\n",
" [ 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1. ]])"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 20 points espacés linéairement entre 0 et 1:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0. , 0.05263158, 0.10526316, 0.15789474, 0.21052632,\n",
" 0.26315789, 0.31578947, 0.36842105, 0.42105263, 0.47368421,\n",
" 0.52631579, 0.57894737, 0.63157895, 0.68421053, 0.73684211,\n",
" 0.78947368, 0.84210526, 0.89473684, 0.94736842, 1. ])"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Indexation et sélection Numpy\n",
"\n",
"Maintenant vous trouverez quelques matrices, il faut les reproduire:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1, 2, 3, 4, 5],\n",
" [ 6, 7, 8, 9, 10],\n",
" [11, 12, 13, 14, 15],\n",
" [16, 17, 18, 19, 20],\n",
" [21, 22, 23, 24, 25]])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# VOICI LA MATRICE MAT\n",
"# A UTILISER POUR LES PROCHAINES TACHES\n",
"import numpy as np\n",
"mat = np.arange(1,26).reshape(5,5)\n",
"mat"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ECRIRE LE CODE ICI QUI REPRODUIT LA SORTIE CI-DESSOUS\n",
"# ATTENTION A NE PAS EXECUTER LA CELLULE CI-DESSOUS, SINON VOUS NE\n",
"# POURREZ PLUS VOIR LA SORTIE ATTENDUE"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[12, 13, 14, 15],\n",
" [17, 18, 19, 20],\n",
" [22, 23, 24, 25]])"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ECRIRE LE CODE ICI QUI REPRODUIT LA SORTIE CI-DESSOUS\n",
"# ATTENTION A NE PAS EXECUTER LA CELLULE CI-DESSOUS, SINON VOUS NE\n",
"# POURREZ PLUS VOIR LA SORTIE ATTENDUE"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ECRIRE LE CODE ICI QUI REPRODUIT LA SORTIE CI-DESSOUS\n",
"# ATTENTION A NE PAS EXECUTER LA CELLULE CI-DESSOUS, SINON VOUS NE\n",
"# POURREZ PLUS VOIR LA SORTIE ATTENDUE"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 2],\n",
" [ 7],\n",
" [12]])"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ECRIRE LE CODE ICI QUI REPRODUIT LA SORTIE CI-DESSOUS\n",
"# ATTENTION A NE PAS EXECUTER LA CELLULE CI-DESSOUS, SINON VOUS NE\n",
"# POURREZ PLUS VOIR LA SORTIE ATTENDUE"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([21, 22, 23, 24, 25])"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ECRIRE LE CODE ICI QUI REPRODUIT LA SORTIE CI-DESSOUS\n",
"# ATTENTION A NE PAS EXECUTER LA CELLULE CI-DESSOUS, SINON VOUS NE\n",
"# POURREZ PLUS VOIR LA SORTIE ATTENDUE"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[16, 17, 18, 19, 20],\n",
" [21, 22, 23, 24, 25]])"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Faire les tâches suivantes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Obtenir la somme de toutes les valeurs de la matrice mat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"325"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Obtenir l'écart-type des valeurs de la matrice mat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7.2111025509279782"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Obtenir la somme de toutes les colonnes de la matrice mat"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([55, 60, 65, 70, 75])"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question Bonus\n",
"\n",
"Nous avons beaucoup travaillé avec des données aléatoires avec numpy, mais y a-t-il un moyen de nous assurer que nous obtenons toujours les mêmes nombres aléatoires ? [Cliquez ici pour un indice](https://www.google.fr/search?q=numpy+random+seed&rlz=1C1CHBF_enUS747US747&oq=numpy+random+seed&aqs=chrome..69i57j69i60j0l4.2087j0j7&sourceid=chrome&ie=UTF-8)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Bon travail!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,961 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# NumPy \n",
"\n",
"NumPy (ou Numpy) est une bibliothèque d'Algèbre Linéaire pour Python, la raison de son importance pour la Finance avec Python, c'est que preque toutes les bibliothèques de l'écosystème Data Science Python sont construites sur un bloc NumPy. De plus nous l'utiliserons pour générer des données pour nos exemples d'analyse plus tard!\n",
"\n",
"Numpy est aussi extrêmement rapide, de part ses liens avec le langage C. Pour pour d'informations sur l'utilisation des tableaux plutôt que des listes, regardez ce post [StackOverflow](http://stackoverflow.com/questions/993984/why-numpy-instead-of-python-lists).\n",
"\n",
"Nous n'apprendrons que les bases de NumPy, pour commencer nous avons besoin de l'installer!"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Instructions d'installation\n",
"\n",
"### NumPy est déjà inclus dans votre environnement! Si vous utilisez l'environnement pyfinance, c'est bon pour vous!\n",
"\n",
"_____\n",
"##### Pour ceux n'utilisant pas l'environnement fourni:\n",
"\n",
"**Il est fortement recommandé d'installer Python à l'aide de la distribution Anaconda pour vous assurer que toutes les dépendances sous-jacentes (comme les bibliothèques Linear Algebra) sont synchronisées avec l'utilisation d'une installation conda. Si vous avez Anaconda, installez NumPy en vous rendant à votre terminal ou à l'invite de commande et en tapant:**\n",
" \n",
" conda install numpy\n",
" \n",
"**Si vous n'avez pas Anaconda et ne pouvez pas l'installer, veuillez vous référer à [Documentation officielle de Numpy sur les différentes instructions d'installation.](http://docs.scipy.org/doc/numpy-1.10.1/user/install.html)**\n",
"\n",
"_____"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Utiliser NumPy\n",
"\n",
"Une fois que vous avez installé NumPy, vous pouvez l'importer sous forme de bibliothèque :"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Numpy a de nombreuses fonctions et capacités intégrées. Nous ne les couvrirons pas toutes, mais nous nous concentrerons plutôt sur certains des aspects les plus importants de Numpy: vecteurs, tableaux, matrices et génération de nombres. Commençons par discuter des tableaux.\n",
"\n",
"# Tableaux Numpy\n",
"\n",
"Les tableaux NumPy sont la principale façon dont nous utiliserons Numpy tout au long du cours. Les tableaux Numpy sont essentiellement de deux types: les vecteurs et les matrices. Les vecteurs sont des tableaux 1-d et les matrices sont 2-d (mais vous devez noter qu'une matrice peut toujours avoir seulement une ligne ou une colonne).\n",
"\n",
"Commençons notre introduction en explorant comment créer des tableaux NumPy.\n",
"\n",
"## Création de tableaux NumPy\n",
"\n",
"### Depuis une liste Python\n",
"\n",
"Nous pouvons créer un tableau en convertissant directement une liste ou une liste de listes:"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 2, 3]"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_list = [1,2,3]\n",
"my_list"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2, 3])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.array(my_list)"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[1, 2, 3], [4, 5, 6], [7, 8, 9]]"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_matrix = [[1,2,3],[4,5,6],[7,8,9]]\n",
"my_matrix"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1, 2, 3],\n",
" [4, 5, 6],\n",
" [7, 8, 9]])"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.array(my_matrix)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Méthodes intégrées\n",
"\n",
"Il existe de nombreuses méthodes intégrées pour générer des tableaux"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### arange\n",
"\n",
"Retourne des valeurs uniformément espacées dans un intervalle donné."
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.arange(0,10)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 2, 4, 6, 8, 10])"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.arange(0,11,2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### zeros et ones\n",
"\n",
"Génère des tableaux de zéros ou de uns"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0., 0., 0.])"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.zeros(3)"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0.],\n",
" [ 0., 0., 0., 0., 0.]])"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.zeros((5,5))"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1., 1., 1.])"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.ones(3)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1., 1., 1.],\n",
" [ 1., 1., 1.],\n",
" [ 1., 1., 1.]])"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.ones((3,3))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### linspace\n",
"Retourne les nombres uniformément espacés sur un intervalle spécifié."
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0., 5., 10.])"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.linspace(0,10,3)"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0. , 0.20408163, 0.40816327, 0.6122449 ,\n",
" 0.81632653, 1.02040816, 1.2244898 , 1.42857143,\n",
" 1.63265306, 1.83673469, 2.04081633, 2.24489796,\n",
" 2.44897959, 2.65306122, 2.85714286, 3.06122449,\n",
" 3.26530612, 3.46938776, 3.67346939, 3.87755102,\n",
" 4.08163265, 4.28571429, 4.48979592, 4.69387755,\n",
" 4.89795918, 5.10204082, 5.30612245, 5.51020408,\n",
" 5.71428571, 5.91836735, 6.12244898, 6.32653061,\n",
" 6.53061224, 6.73469388, 6.93877551, 7.14285714,\n",
" 7.34693878, 7.55102041, 7.75510204, 7.95918367,\n",
" 8.16326531, 8.36734694, 8.57142857, 8.7755102 ,\n",
" 8.97959184, 9.18367347, 9.3877551 , 9.59183673,\n",
" 9.79591837, 10. ])"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.linspace(0,10,50)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## eye\n",
"\n",
"Crée une matrice d'identité"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1., 0., 0., 0.],\n",
" [ 0., 1., 0., 0.],\n",
" [ 0., 0., 1., 0.],\n",
" [ 0., 0., 0., 1.]])"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.eye(4)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Random \n",
"\n",
"Numpy a aussi beaucoup de façons de créer des tableaux de nombres aléatoires:\n",
"\n",
"### rand\n",
"Créez un tableau de la forme donnée et remplissez-le avec\n",
"des échantillons aléatoires provenant d'une distribution uniforme\n",
"sur ``[0, 1)``."
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.11570539, 0.35279769])"
]
},
"execution_count": 47,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.rand(2)"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0.66660768, 0.87589888, 0.12421056, 0.65074126, 0.60260888],\n",
" [ 0.70027668, 0.85572434, 0.8464595 , 0.2735416 , 0.10955384],\n",
" [ 0.0670566 , 0.83267738, 0.9082729 , 0.58249129, 0.12305748],\n",
" [ 0.27948423, 0.66422017, 0.95639833, 0.34238788, 0.9578872 ],\n",
" [ 0.72155386, 0.3035422 , 0.85249683, 0.30414307, 0.79718816]])"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.rand(5,5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### randn\n",
"\n",
"Retourne un échantillon (ou des échantillons) de la distribution \"normale standard\". Contrairement à rand qui est uniforme:"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([-0.27954018, 0.90078368])"
]
},
"execution_count": 48,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.randn(2)"
]
},
{
"cell_type": "code",
"execution_count": 45,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0.70154515, 0.22441999, 1.33563186, 0.82872577, -0.28247509],\n",
" [ 0.64489788, 0.61815094, -0.81693168, -0.30102424, -0.29030574],\n",
" [ 0.8695976 , 0.413755 , 2.20047208, 0.17955692, -0.82159344],\n",
" [ 0.59264235, 1.29869894, -1.18870241, 0.11590888, -0.09181687],\n",
" [-0.96924265, -1.62888685, -2.05787102, -0.29705576, 0.68915542]])"
]
},
"execution_count": 45,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.randn(5,5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### randint\n",
"Retourne les nombres entiers aléatoires de `low` (inclus) à `high` (exclusif)."
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"44"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.randint(1,100)"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([13, 64, 27, 63, 46, 68, 92, 10, 58, 24])"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.randint(1,100,10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Attributs et méthodes des tableaux\n",
"\n",
"Discutons de quelques attributs et méthodes utiles pour un tableau :"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"arr = np.arange(25)\n",
"ranarr = np.random.randint(0,50,10)"
]
},
{
"cell_type": "code",
"execution_count": 56,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n",
" 17, 18, 19, 20, 21, 22, 23, 24])"
]
},
"execution_count": 56,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 12, 41, 17, 49, 2, 46, 3, 19, 39])"
]
},
"execution_count": 57,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Reshape\n",
"Retourne un tableau contenant les mêmes données avec une nouvelle forme."
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0, 1, 2, 3, 4],\n",
" [ 5, 6, 7, 8, 9],\n",
" [10, 11, 12, 13, 14],\n",
" [15, 16, 17, 18, 19],\n",
" [20, 21, 22, 23, 24]])"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr.reshape(5,5)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### max, min, argmax, argmin\n",
"\n",
"Ce sont des méthodes utiles pour trouver des valeurs maximales ou minimales. Ou pour trouver l'emplacement de leur index à l'aide des méthodes argmin ou argmax"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 12, 41, 17, 49, 2, 46, 3, 19, 39])"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"49"
]
},
"execution_count": 61,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr.max()"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"4"
]
},
"execution_count": 62,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr.argmax()"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 63,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr.min()"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"5"
]
},
"execution_count": 60,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ranarr.argmin()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Shape\n",
"\n",
"Shape est un attribut des tableaux (pas une méthode):"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(25,)"
]
},
"execution_count": 65,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Vecteur\n",
"arr.shape"
]
},
{
"cell_type": "code",
"execution_count": 66,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n",
" 17, 18, 19, 20, 21, 22, 23, 24]])"
]
},
"execution_count": 66,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Remarquez les doubles crochets\n",
"arr.reshape(1,25)"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1, 25)"
]
},
"execution_count": 69,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr.reshape(1,25).shape"
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0],\n",
" [ 1],\n",
" [ 2],\n",
" [ 3],\n",
" [ 4],\n",
" [ 5],\n",
" [ 6],\n",
" [ 7],\n",
" [ 8],\n",
" [ 9],\n",
" [10],\n",
" [11],\n",
" [12],\n",
" [13],\n",
" [14],\n",
" [15],\n",
" [16],\n",
" [17],\n",
" [18],\n",
" [19],\n",
" [20],\n",
" [21],\n",
" [22],\n",
" [23],\n",
" [24]])"
]
},
"execution_count": 70,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr.reshape(25,1)"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(25, 1)"
]
},
"execution_count": 76,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr.reshape(25,1).shape"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### dtype\n",
"\n",
"Vous pouvez également saisir le type de données de l'objet dans le tableau:"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"dtype('int64')"
]
},
"execution_count": 75,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr.dtype"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,329 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Opérations NumPy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Arithmétique\n",
"\n",
"Vous pouvez facilement effectuer un tableau avec l'arithmétique tableau, ou scalaire avec l'arithmétique tableau. Voyons quelques exemples :"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"arr = np.arange(0,10)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 2, 4, 6, 8, 10, 12, 14, 16, 18])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr + arr"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 1, 4, 9, 16, 25, 36, 49, 64, 81])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr * arr"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr - arr"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/marci/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:1: RuntimeWarning: invalid value encountered in true_divide\n",
" if __name__ == '__main__':\n"
]
},
{
"data": {
"text/plain": [
"array([ nan, 1., 1., 1., 1., 1., 1., 1., 1., 1.])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Avertissement en cas de division par zéro, mais pas une erreur !\n",
"# Seulement remplacé par nan\n",
"arr/arr"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/marci/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:1: RuntimeWarning: divide by zero encountered in true_divide\n",
" if __name__ == '__main__':\n"
]
},
{
"data": {
"text/plain": [
"array([ inf, 1. , 0.5 , 0.33333333, 0.25 ,\n",
" 0.2 , 0.16666667, 0.14285714, 0.125 , 0.11111111])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Avertissement aussi, mais pas une erreur, remplacé par l'infini\n",
"1/arr"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 1, 8, 27, 64, 125, 216, 343, 512, 729])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr**3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fonctions universelles de tableau\n",
"\n",
"Numpy vient avec beaucoup de [fonctions universelles de tableau](http://docs.scipy.org/doc/numpy/reference/ufuncs.html), qui sont essentiellement juste des opérations mathématiques que vous pouvez utiliser pour effectuer l'opération à travers le tableau. En voici quelques unes :"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0. , 1. , 1.41421356, 1.73205081, 2. ,\n",
" 2.23606798, 2.44948974, 2.64575131, 2.82842712, 3. ])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Prendre la racine carrée\n",
"np.sqrt(arr)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1.00000000e+00, 2.71828183e+00, 7.38905610e+00,\n",
" 2.00855369e+01, 5.45981500e+01, 1.48413159e+02,\n",
" 4.03428793e+02, 1.09663316e+03, 2.98095799e+03,\n",
" 8.10308393e+03])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Calcul exponentiel (e^)\n",
"np.exp(arr)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"9"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.max(arr) # comme arr.max()"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0. , 0.84147098, 0.90929743, 0.14112001, -0.7568025 ,\n",
" -0.95892427, -0.2794155 , 0.6569866 , 0.98935825, 0.41211849])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.sin(arr)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/Users/marci/anaconda/lib/python3.5/site-packages/ipykernel/__main__.py:1: RuntimeWarning: divide by zero encountered in log\n",
" if __name__ == '__main__':\n"
]
},
{
"data": {
"text/plain": [
"array([ -inf, 0. , 0.69314718, 1.09861229, 1.38629436,\n",
" 1.60943791, 1.79175947, 1.94591015, 2.07944154, 2.19722458])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.log(arr)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!\n",
"\n",
"C'est tout ce que nous avons besoin de savoir pour l'instant !"
]
}
],
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,635 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# NumPy Indexing et Selection\n",
"\n",
"Dans cette session, nous discuterons de la façon de sélectionner des éléments ou des groupes d'éléments à partir d'un tableau."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Création d'un tableau simple\n",
"arr = np.arange(0,11)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# afficher\n",
"arr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Indexation et sélection\n",
"La façon la plus simple de choisir un ou plusieurs éléments d'un tableau ressemble beaucoup aux listes python :"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"8"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Obtenir une valeur à un index\n",
"arr[8]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1, 2, 3, 4])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Obtenir des valeurs dans une plage d'entiers\n",
"arr[1:5]"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Obtenir des valeurs dans une plage d'entiers\n",
"arr[0:5]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Broadcasting\n",
"\n",
"Les tableaux Numpy diffèrent d'une liste Python normale en raison de leur capacité à diffuser :"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([100, 100, 100, 100, 100, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Réglage d'une valeur avec plage d'indice (Broadcasting)\n",
"arr[0:5]=100\n",
"\n",
"# afficher\n",
"arr"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Réinitialiser le tableau, nous verrons pourquoi \n",
"# j'ai dû le réinitialiser plus bas.\n",
"arr = np.arange(0,11)\n",
"\n",
"# afficher\n",
"arr"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0, 1, 2, 3, 4, 5])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Remarques importantes sur les tranches (slices)\n",
"slice_of_arr = arr[0:6]\n",
"\n",
"# afficher tranche\n",
"slice_of_arr"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([99, 99, 99, 99, 99, 99])"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Changer de tranche\n",
"slice_of_arr[:] = 99\n",
"\n",
"# Afficher de nouveau\n",
"slice_of_arr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Notez maintenant que les changements se produisent aussi dans notre tableau d'origine !"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([99, 99, 99, 99, 99, 99, 6, 7, 8, 9, 10])"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Les données ne sont pas copiées, c'est une vue du tableau d'origine ! Cela permet d'éviter les problèmes de mémoire !"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([99, 99, 99, 99, 99, 99, 6, 7, 8, 9, 10])"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Pour en obtenir une copie, il faut être explicite\n",
"arr_copy = arr.copy()\n",
"\n",
"arr_copy"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Indexation d'un tableau 2D (matrices)\n",
"\n",
"Le format général est le suivant **arr_2d[row][col]** ou **arr_2d[row,col]**. Je recommande habituellement d'utiliser la notation par virgule pour plus de clarté."
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 5, 10, 15],\n",
" [20, 25, 30],\n",
" [35, 40, 45]])"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr_2d = np.array(([5,10,15],[20,25,30],[35,40,45]))\n",
"\n",
"# afficher\n",
"arr_2d"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([20, 25, 30])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Indexer une ligne\n",
"arr_2d[1]\n"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Le format est arr_2d[row][col] ou arr_2d[row,col]\n",
"\n",
"# Obtenir la valeur d'un élément individuel\n",
"arr_2d[1][0]"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Obtenir la valeur d'un élément individuel\n",
"arr_2d[1,0]"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[10, 15],\n",
" [25, 30]])"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# découpage en tranches d'un tableau 2D\n",
"\n",
"# Forme (2,2) du coin supérieur droit\n",
"arr_2d[:2,1:]"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([35, 40, 45])"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Forme de la rangée du bas\n",
"arr_2d[2]"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([35, 40, 45])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Forme de la rangée du bas\n",
"arr_2d[2,:]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plus d'aide pour l'indexation\n",
"L'indexation d'une matrice 2d peut être un peu confuse au début, surtout lorsque vous commencez à ajouter une taille de pas. Essayez la recherche d'images sur google \"NumPy indexing\" pour trouver des images utiles, comme celle-ci :\n",
"\n",
"<img src= 'https://s2.qwant.com/thumbr/0x380/e/f/c01bff98594466ebc0010d2898208f123a92d43849fb809db543c82f2038c9/Numpy1.jpg?u=https%3A%2F%2Fmedia.geeksforgeeks.org%2Fwp-content%2Fuploads%2FNumpy1.jpg&q=0&b=1&p=0&a=1' width=500/>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Sélection conditionnelle\n",
"\n",
"C'est un concept très fondamental qui se réglera directement par pandas plus tard, assurez-vous de bien comprendre cette partie !\n",
"\n",
"Passons brièvement en revue la façon d'utiliser les parenthèses pour la sélection basée sur des opérateurs de comparaison."
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr = np.arange(1,11)\n",
"arr"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([False, False, False, False, True, True, True, True, True, True], dtype=bool)"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr > 4"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"bool_arr = arr>4"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([False, False, False, False, True, True, True, True, True, True], dtype=bool)"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"bool_arr"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr[bool_arr]"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 3, 4, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"arr[arr>2]"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 3, 4, 5, 6, 7, 8, 9, 10])"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"x = 2\n",
"arr[arr>x]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!\n"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,629 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercices NumPy - Solutions\n",
"Maintenant que nous avons découvert NumPy, testons vos connaissances. Nous commencerons par quelques tâches simples, puis des questions plus complexes.\n",
"\n",
"** REMARQUE IMPORTANTE : Veillez à ne pas exécuter les cellules directement au-dessus de la sortie de résultat attendu, sinon vous risquez de finir par écrire par dessus ! **"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Import NumPy as np"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 10 zéros "
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.zeros(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 10 uns"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.ones(10)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 10 cinq"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([5., 5., 5., 5., 5., 5., 5., 5., 5., 5.])"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.ones(10) * 5"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau d'entiers de 10 à 50"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n",
" 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,\n",
" 44, 45, 46, 47, 48, 49, 50])"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.arange(10,51)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de tous les entiers pairs entre 10 et 50"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,\n",
" 44, 46, 48, 50])"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.arange(10,51,2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer une matrice 3x3 avec les valeurs de 0 à 8"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0, 1, 2],\n",
" [3, 4, 5],\n",
" [6, 7, 8]])"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.arange(0,9).reshape(3,3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer une matrice identité 3x3"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[1., 0., 0.],\n",
" [0., 1., 0.],\n",
" [0., 0., 1.]])"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.eye(3)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Utiliser NumPy pour générer un nombre aléatoire entre 0 et 1"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0.0774109])"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.rand(1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Utiliser NumPy pour générer un tableau de 25 nombres aléatoires échantillonnés à partir d'une distribution normale standard"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.01471837, -0.54119397, 0.61856113, 0.75337696, 0.54470058,\n",
" 0.21793039, 1.12443308, 0.77995286, -0.62594303, -0.61483113,\n",
" 0.27331136, 0.69654147, 0.56232085, -0.05882004, -0.73255901,\n",
" -0.31370757, 1.94487633, -1.27965513, -1.36078982, -0.39200937,\n",
" -0.96238637, 0.47766402, -0.84683412, -1.79296081, -0.62813396])"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.random.randn(25)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer la matrice suivante:"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ],\n",
" [0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2 ],\n",
" [0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3 ],\n",
" [0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4 ],\n",
" [0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5 ],\n",
" [0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6 ],\n",
" [0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7 ],\n",
" [0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8 ],\n",
" [0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9 ],\n",
" [0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1. ]])"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.arange(1,101).reshape(10,10)/100"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 20 points espacés linéairement entre 0 et 1:"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([0. , 0.05263158, 0.10526316, 0.15789474, 0.21052632,\n",
" 0.26315789, 0.31578947, 0.36842105, 0.42105263, 0.47368421,\n",
" 0.52631579, 0.57894737, 0.63157895, 0.68421053, 0.73684211,\n",
" 0.78947368, 0.84210526, 0.89473684, 0.94736842, 1. ])"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.linspace(0,1,20)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Indexation et sélection Numpy\n",
"\n",
"Maintenant vous trouverez quelques matrices, il faut les reproduire:"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1, 2, 3, 4, 5],\n",
" [ 6, 7, 8, 9, 10],\n",
" [11, 12, 13, 14, 15],\n",
" [16, 17, 18, 19, 20],\n",
" [21, 22, 23, 24, 25]])"
]
},
"execution_count": 27,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# VOICI LA MATRICE MAT\n",
"# A UTILISER POUR LES PROCHAINES TACHES\n",
"import numpy as np\n",
"mat = np.arange(1,26).reshape(5,5)\n",
"mat"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[12, 13, 14, 15],\n",
" [17, 18, 19, 20],\n",
" [22, 23, 24, 25]])"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat[2:,1:]"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat[3,4]"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 2],\n",
" [ 7],\n",
" [12]])"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat[:3,1:2]"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([21, 22, 23, 24, 25])"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat[4,:]"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[16, 17, 18, 19, 20],\n",
" [21, 22, 23, 24, 25]])"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat[3:,:]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Faire les tâches suivantes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Obtenir la somme de toutes les valeurs de la matrice mat"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"325"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat.sum()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Obtenir l'écart-type des valeurs de la matrice mat"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7.211102550927978"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat.std()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Obtenir la somme de toutes les colonnes de la matrice mat"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([55, 60, 65, 70, 75])"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mat.sum(axis=0)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question Bonus\n",
"\n",
"Nous avons beaucoup travaillé avec des données aléatoires avec numpy, mais y a-t-il un moyen de nous assurer que nous obtenons toujours les mêmes nombres aléatoires ? [Cliquez ici pour un indice](https://www.google.fr/search?q=numpy+random+seed&rlz=1C1CHBF_enUS747US747&oq=numpy+random+seed&aqs=chrome..69i57j69i60j0l4.2087j0j7&sourceid=chrome&ie=UTF-8)"
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [],
"source": [
"np.random.seed(101)"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Bon travail!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.7.7"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,800 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Exercices NumPy\n",
"Maintenant que nous avons découvert NumPy, testons vos connaissances. Nous commencerons par quelques tâches simples, puis des questions plus complexes.\n",
"\n",
"**REMARQUE IMPORTANTE : Veillez à ne pas exécuter les cellules directement au-dessus de la sortie de résultat attendu, sinon vous risquez de finir par écrire par dessus !**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Import NumPy as np"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 10 zéros "
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 10 uns"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1., 1., 1., 1., 1., 1., 1., 1., 1., 1.])"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 10 cinq"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 5., 5., 5., 5., 5., 5., 5., 5., 5., 5.])"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau d'entiers de 10 à 50"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26,\n",
" 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,\n",
" 44, 45, 46, 47, 48, 49, 50])"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de tous les entiers pairs entre 10 et 50"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42,\n",
" 44, 46, 48, 50])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer une matrice 3x3 avec les valeurs de 0 à 8"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[0, 1, 2],\n",
" [3, 4, 5],\n",
" [6, 7, 8]])"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer une matrice identité 3x3"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1., 0., 0.],\n",
" [ 0., 1., 0.],\n",
" [ 0., 0., 1.]])"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Utiliser NumPy pour générer un nombre aléatoire entre 0 et 1"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0.42829726])"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Utiliser NumPy pour générer un tableau de 25 nombres aléatoires échantillonnés à partir d'une distribution normale standard"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 1.32031013, 1.6798602 , -0.42985892, -1.53116655, 0.85753232,\n",
" 0.87339938, 0.35668636, -1.47491157, 0.15349697, 0.99530727,\n",
" -0.94865451, -1.69174783, 1.57525349, -0.70615234, 0.10991879,\n",
" -0.49478947, 1.08279872, 0.76488333, -2.3039931 , 0.35401124,\n",
" -0.45454399, -0.64754649, -0.29391671, 0.02339861, 0.38272124])"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer la matrice suivante:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1 ],\n",
" [ 0.11, 0.12, 0.13, 0.14, 0.15, 0.16, 0.17, 0.18, 0.19, 0.2 ],\n",
" [ 0.21, 0.22, 0.23, 0.24, 0.25, 0.26, 0.27, 0.28, 0.29, 0.3 ],\n",
" [ 0.31, 0.32, 0.33, 0.34, 0.35, 0.36, 0.37, 0.38, 0.39, 0.4 ],\n",
" [ 0.41, 0.42, 0.43, 0.44, 0.45, 0.46, 0.47, 0.48, 0.49, 0.5 ],\n",
" [ 0.51, 0.52, 0.53, 0.54, 0.55, 0.56, 0.57, 0.58, 0.59, 0.6 ],\n",
" [ 0.61, 0.62, 0.63, 0.64, 0.65, 0.66, 0.67, 0.68, 0.69, 0.7 ],\n",
" [ 0.71, 0.72, 0.73, 0.74, 0.75, 0.76, 0.77, 0.78, 0.79, 0.8 ],\n",
" [ 0.81, 0.82, 0.83, 0.84, 0.85, 0.86, 0.87, 0.88, 0.89, 0.9 ],\n",
" [ 0.91, 0.92, 0.93, 0.94, 0.95, 0.96, 0.97, 0.98, 0.99, 1. ]])"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Créer un tableau de 20 points espacés linéairement entre 0 et 1:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([ 0. , 0.05263158, 0.10526316, 0.15789474, 0.21052632,\n",
" 0.26315789, 0.31578947, 0.36842105, 0.42105263, 0.47368421,\n",
" 0.52631579, 0.57894737, 0.63157895, 0.68421053, 0.73684211,\n",
" 0.78947368, 0.84210526, 0.89473684, 0.94736842, 1. ])"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Indexation et sélection Numpy\n",
"\n",
"Maintenant vous trouverez quelques matrices, il faut les reproduire:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 1, 2, 3, 4, 5],\n",
" [ 6, 7, 8, 9, 10],\n",
" [11, 12, 13, 14, 15],\n",
" [16, 17, 18, 19, 20],\n",
" [21, 22, 23, 24, 25]])"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# VOICI LA MATRICE MAT\n",
"# A UTILISER POUR LES PROCHAINES TACHES\n",
"import numpy as np\n",
"mat = np.arange(1,26).reshape(5,5)\n",
"mat"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ECRIRE LE CODE ICI QUI REPRODUIT LA SORTIE CI-DESSOUS\n",
"# ATTENTION A NE PAS EXECUTER LA CELLULE CI-DESSOUS, SINON VOUS NE\n",
"# POURREZ PLUS VOIR LA SORTIE ATTENDUE"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[12, 13, 14, 15],\n",
" [17, 18, 19, 20],\n",
" [22, 23, 24, 25]])"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ECRIRE LE CODE ICI QUI REPRODUIT LA SORTIE CI-DESSOUS\n",
"# ATTENTION A NE PAS EXECUTER LA CELLULE CI-DESSOUS, SINON VOUS NE\n",
"# POURREZ PLUS VOIR LA SORTIE ATTENDUE"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"20"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ECRIRE LE CODE ICI QUI REPRODUIT LA SORTIE CI-DESSOUS\n",
"# ATTENTION A NE PAS EXECUTER LA CELLULE CI-DESSOUS, SINON VOUS NE\n",
"# POURREZ PLUS VOIR LA SORTIE ATTENDUE"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[ 2],\n",
" [ 7],\n",
" [12]])"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ECRIRE LE CODE ICI QUI REPRODUIT LA SORTIE CI-DESSOUS\n",
"# ATTENTION A NE PAS EXECUTER LA CELLULE CI-DESSOUS, SINON VOUS NE\n",
"# POURREZ PLUS VOIR LA SORTIE ATTENDUE"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([21, 22, 23, 24, 25])"
]
},
"execution_count": 46,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# ECRIRE LE CODE ICI QUI REPRODUIT LA SORTIE CI-DESSOUS\n",
"# ATTENTION A NE PAS EXECUTER LA CELLULE CI-DESSOUS, SINON VOUS NE\n",
"# POURREZ PLUS VOIR LA SORTIE ATTENDUE"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[16, 17, 18, 19, 20],\n",
" [21, 22, 23, 24, 25]])"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Faire les tâches suivantes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Obtenir la somme de toutes les valeurs de la matrice mat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"325"
]
},
"execution_count": 50,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Obtenir l'écart-type des valeurs de la matrice mat"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"7.2111025509279782"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Obtenir la somme de toutes les colonnes de la matrice mat"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 53,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([55, 60, 65, 70, 75])"
]
},
"execution_count": 53,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Question Bonus\n",
"\n",
"Nous avons beaucoup travaillé avec des données aléatoires avec numpy, mais y a-t-il un moyen de nous assurer que nous obtenons toujours les mêmes nombres aléatoires ? [Cliquez ici pour un indice](https://www.google.fr/search?q=numpy+random+seed&rlz=1C1CHBF_enUS747US747&oq=numpy+random+seed&aqs=chrome..69i57j69i60j0l4.2087j0j7&sourceid=chrome&ie=UTF-8)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Bon travail!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,62 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>\n",
"___"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Introduction to Pandas\n",
"\n",
"In this section of the course we will learn how to use pandas for data analysis. You can think of pandas as an extremely powerful version of Excel, with a lot more features. In this section of the course, you should go through the notebooks in this order:\n",
"\n",
"* Introduction to Pandas\n",
"* Series\n",
"* DataFrames\n",
"* Missing Data\n",
"* GroupBy\n",
"* Merging,Joining,and Concatenating\n",
"* Operations\n",
"* Data Input and Output"
]
},
{
"cell_type": "markdown",
"metadata": {},
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@ -0,0 +1,464 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>\n",
"___\n",
"# Series"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The first main data type we will learn about for pandas is the Series data type. Let's import Pandas and explore the Series object.\n",
"\n",
"A Series is very similar to a NumPy array (in fact it is built on top of the NumPy array object). What differentiates the NumPy array from a Series, is that a Series can have axis labels, meaning it can be indexed by a label, instead of just a number location. It also doesn't need to hold numeric data, it can hold any arbitrary Python Object.\n",
"\n",
"Let's explore this concept through some examples:"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Creating a Series\n",
"\n",
"You can convert a list,numpy array, or dictionary to a Series:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"labels = ['a','b','c']\n",
"my_list = [10,20,30]\n",
"arr = np.array([10,20,30])\n",
"d = {'a':10,'b':20,'c':30}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"** Using Lists**"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0 10\n",
"1 20\n",
"2 30\n",
"dtype: int64"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.Series(data=my_list)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"a 10\n",
"b 20\n",
"c 30\n",
"dtype: int64"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.Series(data=my_list,index=labels)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"a 10\n",
"b 20\n",
"c 30\n",
"dtype: int64"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.Series(my_list,labels)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"** NumPy Arrays **"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0 10\n",
"1 20\n",
"2 30\n",
"dtype: int64"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.Series(arr)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"a 10\n",
"b 20\n",
"c 30\n",
"dtype: int64"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.Series(arr,labels)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"** Dictionary**"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"a 10\n",
"b 20\n",
"c 30\n",
"dtype: int64"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.Series(d)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Data in a Series\n",
"\n",
"A pandas Series can hold a variety of object types:"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0 a\n",
"1 b\n",
"2 c\n",
"dtype: object"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"pd.Series(data=labels)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0 <built-in function sum>\n",
"1 <built-in function print>\n",
"2 <built-in function len>\n",
"dtype: object"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Even functions (although unlikely that you will use this)\n",
"pd.Series([sum,print,len])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using an Index\n",
"\n",
"The key to using a Series is understanding its index. Pandas makes use of these index names or numbers by allowing for fast look ups of information (works like a hash table or dictionary).\n",
"\n",
"Let's see some examples of how to grab information from a Series. Let us create two sereis, ser1 and ser2:"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"ser1 = pd.Series([1,2,3,4],index = ['USA', 'Germany','USSR', 'Japan']) "
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"USA 1\n",
"Germany 2\n",
"USSR 3\n",
"Japan 4\n",
"dtype: int64"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ser1"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"ser2 = pd.Series([1,2,5,4],index = ['USA', 'Germany','Italy', 'Japan']) "
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"USA 1\n",
"Germany 2\n",
"Italy 5\n",
"Japan 4\n",
"dtype: int64"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ser2"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ser1['USA']"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"Operations are then also done based off of index:"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Germany 4.0\n",
"Italy NaN\n",
"Japan 8.0\n",
"USA 2.0\n",
"USSR NaN\n",
"dtype: float64"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ser1 + ser2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's stop here for now and move on to DataFrames, which will expand on the concept of Series!\n",
"# Great Job!"
]
}
],
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,367 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>\n",
"___"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Missing Data\n",
"\n",
"Let's show a few convenient methods to deal with Missing Data in pandas:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df = pd.DataFrame({'A':[1,2,np.nan],\n",
" 'B':[5,np.nan,np.nan],\n",
" 'C':[1,2,3]})"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\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.0</td>\n",
" <td>5.0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>3</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B C\n",
"0 1.0 5.0 1\n",
"1 2.0 NaN 2\n",
"2 NaN NaN 3"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\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.0</td>\n",
" <td>5.0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B C\n",
"0 1.0 5.0 1"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dropna()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>C</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>3</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" C\n",
"0 1\n",
"1 2\n",
"2 3"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dropna(axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\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.0</td>\n",
" <td>5.0</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2.0</td>\n",
" <td>NaN</td>\n",
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B C\n",
"0 1.0 5.0 1\n",
"1 2.0 NaN 2"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.dropna(thresh=2)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\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>5</td>\n",
" <td>1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>2</td>\n",
" <td>FILL VALUE</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>FILL VALUE</td>\n",
" <td>FILL VALUE</td>\n",
" <td>3</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B C\n",
"0 1 5 1\n",
"1 2 FILL VALUE 2\n",
"2 FILL VALUE FILL VALUE 3"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.fillna(value='FILL VALUE')"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0 1.0\n",
"1 2.0\n",
"2 1.5\n",
"Name: A, dtype: float64"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df['A'].fillna(value=df['A'].mean())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Great Job!"
]
}
],
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@ -0,0 +1,891 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>\n",
"___"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Groupby\n",
"\n",
"The groupby method allows you to group rows of data together and call aggregate functions"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"# Create dataframe\n",
"data = {'Company':['GOOG','GOOG','MSFT','MSFT','FB','FB'],\n",
" 'Person':['Sam','Charlie','Amy','Vanessa','Carl','Sarah'],\n",
" 'Sales':[200,120,340,124,243,350]}"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df = pd.DataFrame(data)"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Company</th>\n",
" <th>Person</th>\n",
" <th>Sales</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>GOOG</td>\n",
" <td>Sam</td>\n",
" <td>200</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>GOOG</td>\n",
" <td>Charlie</td>\n",
" <td>120</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>MSFT</td>\n",
" <td>Amy</td>\n",
" <td>340</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>MSFT</td>\n",
" <td>Vanessa</td>\n",
" <td>124</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>FB</td>\n",
" <td>Carl</td>\n",
" <td>243</td>\n",
" </tr>\n",
" <tr>\n",
" <th>5</th>\n",
" <td>FB</td>\n",
" <td>Sarah</td>\n",
" <td>350</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Company Person Sales\n",
"0 GOOG Sam 200\n",
"1 GOOG Charlie 120\n",
"2 MSFT Amy 340\n",
"3 MSFT Vanessa 124\n",
"4 FB Carl 243\n",
"5 FB Sarah 350"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"** Now you can use the .groupby() method to group rows together based off of a column name. For instance let's group based off of Company. This will create a DataFrameGroupBy object:**"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<pandas.core.groupby.DataFrameGroupBy object at 0x113014128>"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.groupby('Company')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can save this object as a new variable:"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"by_comp = df.groupby(\"Company\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"And then call aggregate methods off the object:"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Sales</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Company</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>FB</th>\n",
" <td>296.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>GOOG</th>\n",
" <td>160.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>MSFT</th>\n",
" <td>232.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Sales\n",
"Company \n",
"FB 296.5\n",
"GOOG 160.0\n",
"MSFT 232.0"
]
},
"execution_count": 36,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"by_comp.mean()"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Sales</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Company</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>FB</th>\n",
" <td>296.5</td>\n",
" </tr>\n",
" <tr>\n",
" <th>GOOG</th>\n",
" <td>160.0</td>\n",
" </tr>\n",
" <tr>\n",
" <th>MSFT</th>\n",
" <td>232.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Sales\n",
"Company \n",
"FB 296.5\n",
"GOOG 160.0\n",
"MSFT 232.0"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.groupby('Company').mean()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"More examples of aggregate methods:"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Sales</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Company</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>FB</th>\n",
" <td>75.660426</td>\n",
" </tr>\n",
" <tr>\n",
" <th>GOOG</th>\n",
" <td>56.568542</td>\n",
" </tr>\n",
" <tr>\n",
" <th>MSFT</th>\n",
" <td>152.735065</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Sales\n",
"Company \n",
"FB 75.660426\n",
"GOOG 56.568542\n",
"MSFT 152.735065"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"by_comp.std()"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Person</th>\n",
" <th>Sales</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Company</th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>FB</th>\n",
" <td>Carl</td>\n",
" <td>243</td>\n",
" </tr>\n",
" <tr>\n",
" <th>GOOG</th>\n",
" <td>Charlie</td>\n",
" <td>120</td>\n",
" </tr>\n",
" <tr>\n",
" <th>MSFT</th>\n",
" <td>Amy</td>\n",
" <td>124</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Person Sales\n",
"Company \n",
"FB Carl 243\n",
"GOOG Charlie 120\n",
"MSFT Amy 124"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"by_comp.min()"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Person</th>\n",
" <th>Sales</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Company</th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>FB</th>\n",
" <td>Sarah</td>\n",
" <td>350</td>\n",
" </tr>\n",
" <tr>\n",
" <th>GOOG</th>\n",
" <td>Sam</td>\n",
" <td>200</td>\n",
" </tr>\n",
" <tr>\n",
" <th>MSFT</th>\n",
" <td>Vanessa</td>\n",
" <td>340</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Person Sales\n",
"Company \n",
"FB Sarah 350\n",
"GOOG Sam 200\n",
"MSFT Vanessa 340"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"by_comp.max()"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Person</th>\n",
" <th>Sales</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Company</th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>FB</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>GOOG</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>MSFT</th>\n",
" <td>2</td>\n",
" <td>2</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Person Sales\n",
"Company \n",
"FB 2 2\n",
"GOOG 2 2\n",
"MSFT 2 2"
]
},
"execution_count": 41,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"by_comp.count()"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th></th>\n",
" <th>Sales</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Company</th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"8\" valign=\"top\">FB</th>\n",
" <th>count</th>\n",
" <td>2.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>296.500000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>75.660426</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>243.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>269.750000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>296.500000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>323.250000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>350.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"8\" valign=\"top\">GOOG</th>\n",
" <th>count</th>\n",
" <td>2.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>160.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>56.568542</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>120.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>140.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>160.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>180.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>200.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"8\" valign=\"top\">MSFT</th>\n",
" <th>count</th>\n",
" <td>2.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>mean</th>\n",
" <td>232.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>std</th>\n",
" <td>152.735065</td>\n",
" </tr>\n",
" <tr>\n",
" <th>min</th>\n",
" <td>124.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>25%</th>\n",
" <td>178.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>50%</th>\n",
" <td>232.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>75%</th>\n",
" <td>286.000000</td>\n",
" </tr>\n",
" <tr>\n",
" <th>max</th>\n",
" <td>340.000000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Sales\n",
"Company \n",
"FB count 2.000000\n",
" mean 296.500000\n",
" std 75.660426\n",
" min 243.000000\n",
" 25% 269.750000\n",
" 50% 296.500000\n",
" 75% 323.250000\n",
" max 350.000000\n",
"GOOG count 2.000000\n",
" mean 160.000000\n",
" std 56.568542\n",
" min 120.000000\n",
" 25% 140.000000\n",
" 50% 160.000000\n",
" 75% 180.000000\n",
" max 200.000000\n",
"MSFT count 2.000000\n",
" mean 232.000000\n",
" std 152.735065\n",
" min 124.000000\n",
" 25% 178.000000\n",
" 50% 232.000000\n",
" 75% 286.000000\n",
" max 340.000000"
]
},
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"by_comp.describe()"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr>\n",
" <th>Company</th>\n",
" <th colspan=\"8\" halign=\"left\">FB</th>\n",
" <th colspan=\"5\" halign=\"left\">GOOG</th>\n",
" <th colspan=\"8\" halign=\"left\">MSFT</th>\n",
" </tr>\n",
" <tr>\n",
" <th></th>\n",
" <th>count</th>\n",
" <th>mean</th>\n",
" <th>std</th>\n",
" <th>min</th>\n",
" <th>25%</th>\n",
" <th>50%</th>\n",
" <th>75%</th>\n",
" <th>max</th>\n",
" <th>count</th>\n",
" <th>mean</th>\n",
" <th>...</th>\n",
" <th>75%</th>\n",
" <th>max</th>\n",
" <th>count</th>\n",
" <th>mean</th>\n",
" <th>std</th>\n",
" <th>min</th>\n",
" <th>25%</th>\n",
" <th>50%</th>\n",
" <th>75%</th>\n",
" <th>max</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Sales</th>\n",
" <td>2.0</td>\n",
" <td>296.5</td>\n",
" <td>75.660426</td>\n",
" <td>243.0</td>\n",
" <td>269.75</td>\n",
" <td>296.5</td>\n",
" <td>323.25</td>\n",
" <td>350.0</td>\n",
" <td>2.0</td>\n",
" <td>160.0</td>\n",
" <td>...</td>\n",
" <td>180.0</td>\n",
" <td>200.0</td>\n",
" <td>2.0</td>\n",
" <td>232.0</td>\n",
" <td>152.735065</td>\n",
" <td>124.0</td>\n",
" <td>178.0</td>\n",
" <td>232.0</td>\n",
" <td>286.0</td>\n",
" <td>340.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1 rows × 24 columns</p>\n",
"</div>"
],
"text/plain": [
"Company FB GOOG \\\n",
" count mean std min 25% 50% 75% max count \n",
"Sales 2.0 296.5 75.660426 243.0 269.75 296.5 323.25 350.0 2.0 \n",
"\n",
"Company ... MSFT \\\n",
" mean ... 75% max count mean std min 25% \n",
"Sales 160.0 ... 180.0 200.0 2.0 232.0 152.735065 124.0 178.0 \n",
"\n",
"Company \n",
" 50% 75% max \n",
"Sales 232.0 286.0 340.0 \n",
"\n",
"[1 rows x 24 columns]"
]
},
"execution_count": 43,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"by_comp.describe().transpose()"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>count</th>\n",
" <th>mean</th>\n",
" <th>std</th>\n",
" <th>min</th>\n",
" <th>25%</th>\n",
" <th>50%</th>\n",
" <th>75%</th>\n",
" <th>max</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Sales</th>\n",
" <td>2.0</td>\n",
" <td>160.0</td>\n",
" <td>56.568542</td>\n",
" <td>120.0</td>\n",
" <td>140.0</td>\n",
" <td>160.0</td>\n",
" <td>180.0</td>\n",
" <td>200.0</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" count mean std min 25% 50% 75% max\n",
"Sales 2.0 160.0 56.568542 120.0 140.0 160.0 180.0 200.0"
]
},
"execution_count": 44,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"by_comp.describe().transpose()['GOOG']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Great Job!"
]
}
],
"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.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,45 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Introduction à Pandas\n",
"\n",
"Dans cette section du cours, nous apprendrons comment utiliser pandas pour l'analyse des données. Vous pouvez considérer pandas comme une version extrêmement puissante d'Excel, avec beaucoup plus de fonctionnalités. Dans cette section du cours, vous devriez passer en revue les notebooks dans cet ordre :\n",
"\n",
"* Introduction à Pandas\n",
"* Series\n",
"* DataFrames\n",
"* Données manquantes\n",
"* GroupBy\n",
"* Merge, Join et Concat\n",
"* Opérations\n",
"* Data Input et Output"
]
}
],
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

430
03-Pandas/02-Series.ipynb Normal file
View File

@ -0,0 +1,430 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Series"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Le premier grand type de données que nous apprendrons sur pandas est le type de données de la série. Importez Pandas et explorez l'objet Série.\n",
"\n",
"Une série est très similaire à un tableau NumPy (en fait, elle est construite sur l'objet tableau NumPy). Ce qui différencie le tableau NumPy d'une série, c'est qu'une série peut avoir des étiquettes d'axes, ce qui signifie qu'elle peut être indexée par une étiquette, au lieu d'un simple emplacement de numéro. Il n'a pas non plus besoin de contenir des données numériques, il peut contenir n'importe quel objet Python arbitraire.\n",
"\n",
"Examinons ce concept à travers quelques exemples :"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Création d'une d'un objet Series\n",
"\n",
"Vous pouvez convertir une liste, un tableau numpy ou un dictionnaire en série :"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"labels = ['a','b','c']\n",
"my_list = [10,20,30]\n",
"arr = np.array([10,20,30])\n",
"d = {'a':10,'b':20,'c':30}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**en utilisant des listes**"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0 10\n",
"1 20\n",
"2 30\n",
"dtype: int64"
]
},
"metadata": {},
"execution_count": 3
}
],
"source": [
"pd.Series(data=my_list)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"a 10\n",
"b 20\n",
"c 30\n",
"dtype: int64"
]
},
"metadata": {},
"execution_count": 4
}
],
"source": [
"pd.Series(data=my_list,index=labels)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"a 10\n",
"b 20\n",
"c 30\n",
"dtype: int64"
]
},
"metadata": {},
"execution_count": 5
}
],
"source": [
"pd.Series(my_list,labels)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**en utilisant des tableaux NumPy**"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0 10\n",
"1 20\n",
"2 30\n",
"dtype: int32"
]
},
"metadata": {},
"execution_count": 6
}
],
"source": [
"pd.Series(arr)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"a 10\n",
"b 20\n",
"c 30\n",
"dtype: int32"
]
},
"metadata": {},
"execution_count": 7
}
],
"source": [
"pd.Series(arr,labels)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**en utilisant des dictionnaires**"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"a 10\n",
"b 20\n",
"c 30\n",
"dtype: int64"
]
},
"metadata": {},
"execution_count": 8
}
],
"source": [
"pd.Series(d)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Données dans une Série\n",
"\n",
"Une série pandas peut contenir une variété de types d'objets :"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0 a\n",
"1 b\n",
"2 c\n",
"dtype: object"
]
},
"metadata": {},
"execution_count": 9
}
],
"source": [
"pd.Series(data=labels)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0 <built-in function sum>\n",
"1 <built-in function print>\n",
"2 <built-in function len>\n",
"dtype: object"
]
},
"metadata": {},
"execution_count": 10
}
],
"source": [
"# Même es fonctions (bien qu'il soit peu probable que vous l'utilisiez)\n",
"pd.Series([sum,print,len])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## En utilisant un Index\n",
"\n",
"La clé de l'utilisation d'une série est la compréhension de son index. Pandas utilise ces noms ou numéros d'index en permettant une recherche rapide de l'information (fonctionne comme une table de hachage ou un dictionnaire).\n",
"\n",
"Voyons quelques exemples de la façon d'extraire des informations d'une série. Créons deux séries ser1 et ser2 :"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"ser1 = pd.Series([1,2,3,4],index = ['USA', 'Germany','France', 'Japan']) "
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"USA 1\n",
"Germany 2\n",
"France 3\n",
"Japan 4\n",
"dtype: int64"
]
},
"metadata": {},
"execution_count": 12
}
],
"source": [
"ser1"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"ser2 = pd.Series([1,2,5,4],index = ['USA', 'Germany','Italy', 'Japan']) "
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"USA 1\n",
"Germany 2\n",
"Italy 5\n",
"Japan 4\n",
"dtype: int64"
]
},
"metadata": {},
"execution_count": 14
}
],
"source": [
"ser2"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"1"
]
},
"metadata": {},
"execution_count": 15
}
],
"source": [
"ser1['USA']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Les opérations sont alors également effectuées sur la base de l'index :"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"France NaN\n",
"Germany 4.0\n",
"Italy NaN\n",
"Japan 8.0\n",
"USA 2.0\n",
"dtype: float64"
]
},
"metadata": {},
"execution_count": 16
}
],
"source": [
"ser1 + ser2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Arrêtons-nous ici pour l'instant et passons aux DataFrames, qui vont développer le concept de Série !\n",
"# Bon travail!"
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.9 64-bit ('pyfinance': conda)",
"metadata": {
"interpreter": {
"hash": "e89404a230d8800c54ad520c7b67d1bd9bb833a07b37dd3e521a178a3dc34904"
}
}
},
"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.7.9-final"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,206 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Données manquantes\n",
"\n",
"Montrons quelques méthodes pratiques pour traiter les données manquantes dans pandas :"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame({'A':[1,2,np.nan],\n",
" 'B':[5,np.nan,np.nan],\n",
" 'C':[1,2,3]})"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C\n",
"0 1.0 5.0 1\n",
"1 2.0 NaN 2\n",
"2 NaN NaN 3"
],
"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.0</td>\n <td>5.0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2.0</td>\n <td>NaN</td>\n <td>2</td>\n </tr>\n <tr>\n <th>2</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>3</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 3
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C\n",
"0 1.0 5.0 1"
],
"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.0</td>\n <td>5.0</td>\n <td>1</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 4
}
],
"source": [
"df.dropna()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" C\n",
"0 1\n",
"1 2\n",
"2 3"
],
"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>C</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 5
}
],
"source": [
"df.dropna(axis=1)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C\n",
"0 1.0 5.0 1\n",
"1 2.0 NaN 2"
],
"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.0</td>\n <td>5.0</td>\n <td>1</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2.0</td>\n <td>NaN</td>\n <td>2</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 6
}
],
"source": [
"df.dropna(thresh=2)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C\n",
"0 1 5 1\n",
"1 2 Valeur de remplacement 2\n",
"2 Valeur de remplacement Valeur de remplacement 3"
],
"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>5</td>\n <td>1</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>Valeur de remplacement</td>\n <td>2</td>\n </tr>\n <tr>\n <th>2</th>\n <td>Valeur de remplacement</td>\n <td>Valeur de remplacement</td>\n <td>3</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 7
}
],
"source": [
"df.fillna(value='Valeur de remplacement')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0 1.0\n",
"1 2.0\n",
"2 1.5\n",
"Name: A, dtype: float64"
]
},
"metadata": {},
"execution_count": 8
}
],
"source": [
"df['A'].fillna(value=df['A'].mean())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!"
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.9 64-bit ('pyfinance': conda)",
"metadata": {
"interpreter": {
"hash": "e89404a230d8800c54ad520c7b67d1bd9bb833a07b37dd3e521a178a3dc34904"
}
}
},
"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.7.9-final"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

390
03-Pandas/05-Groupby.ipynb Normal file
View File

@ -0,0 +1,390 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Groupby\n",
"\n",
"La méthode de regroupement par groupe vous permet de regrouper des lignes de données et d'appeler des fonctions d'agrégation."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"# Création dataframe\n",
"data = {'Company':['GOOG','GOOG','MSFT','MSFT','FB','FB'],\n",
" 'Person':['Sam','Charlie','Amy','Vanessa','Carl','Sarah'],\n",
" 'Sales':[200,120,340,124,243,350]}"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame(data)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Company Person Sales\n",
"0 GOOG Sam 200\n",
"1 GOOG Charlie 120\n",
"2 MSFT Amy 340\n",
"3 MSFT Vanessa 124\n",
"4 FB Carl 243\n",
"5 FB Sarah 350"
],
"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>Company</th>\n <th>Person</th>\n <th>Sales</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>GOOG</td>\n <td>Sam</td>\n <td>200</td>\n </tr>\n <tr>\n <th>1</th>\n <td>GOOG</td>\n <td>Charlie</td>\n <td>120</td>\n </tr>\n <tr>\n <th>2</th>\n <td>MSFT</td>\n <td>Amy</td>\n <td>340</td>\n </tr>\n <tr>\n <th>3</th>\n <td>MSFT</td>\n <td>Vanessa</td>\n <td>124</td>\n </tr>\n <tr>\n <th>4</th>\n <td>FB</td>\n <td>Carl</td>\n <td>243</td>\n </tr>\n <tr>\n <th>5</th>\n <td>FB</td>\n <td>Sarah</td>\n <td>350</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 3
}
],
"source": [
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Maintenant vous pouvez utiliser la méthode .groupby() pour regrouper les lignes en fonction d'un nom de colonne. Par exemple, groupons les personnes par société. Ceci créera un objet DataFrameGroupBy :**"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"<pandas.core.groupby.generic.DataFrameGroupBy object at 0x00000166211DA848>"
]
},
"metadata": {},
"execution_count": 4
}
],
"source": [
"df.groupby('Company')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Vous pouvez sauvegarder cet objet comme nouvelle variable :"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"by_comp = df.groupby(\"Company\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Et ensuite, appelez les méthodes d'agrégation sur l'objet :"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Sales\n",
"Company \n",
"FB 296.5\n",
"GOOG 160.0\n",
"MSFT 232.0"
],
"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>Sales</th>\n </tr>\n <tr>\n <th>Company</th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>FB</th>\n <td>296.5</td>\n </tr>\n <tr>\n <th>GOOG</th>\n <td>160.0</td>\n </tr>\n <tr>\n <th>MSFT</th>\n <td>232.0</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 6
}
],
"source": [
"by_comp.mean()"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Sales\n",
"Company \n",
"FB 296.5\n",
"GOOG 160.0\n",
"MSFT 232.0"
],
"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>Sales</th>\n </tr>\n <tr>\n <th>Company</th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>FB</th>\n <td>296.5</td>\n </tr>\n <tr>\n <th>GOOG</th>\n <td>160.0</td>\n </tr>\n <tr>\n <th>MSFT</th>\n <td>232.0</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 7
}
],
"source": [
"df.groupby('Company').mean()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Autres exemples de méthodes d'agrégation :"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Sales\n",
"Company \n",
"FB 75.660426\n",
"GOOG 56.568542\n",
"MSFT 152.735065"
],
"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>Sales</th>\n </tr>\n <tr>\n <th>Company</th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>FB</th>\n <td>75.660426</td>\n </tr>\n <tr>\n <th>GOOG</th>\n <td>56.568542</td>\n </tr>\n <tr>\n <th>MSFT</th>\n <td>152.735065</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 8
}
],
"source": [
"by_comp.std()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Person Sales\n",
"Company \n",
"FB Carl 243\n",
"GOOG Charlie 120\n",
"MSFT Amy 124"
],
"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>Person</th>\n <th>Sales</th>\n </tr>\n <tr>\n <th>Company</th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>FB</th>\n <td>Carl</td>\n <td>243</td>\n </tr>\n <tr>\n <th>GOOG</th>\n <td>Charlie</td>\n <td>120</td>\n </tr>\n <tr>\n <th>MSFT</th>\n <td>Amy</td>\n <td>124</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 9
}
],
"source": [
"by_comp.min()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Person Sales\n",
"Company \n",
"FB Sarah 350\n",
"GOOG Sam 200\n",
"MSFT Vanessa 340"
],
"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>Person</th>\n <th>Sales</th>\n </tr>\n <tr>\n <th>Company</th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>FB</th>\n <td>Sarah</td>\n <td>350</td>\n </tr>\n <tr>\n <th>GOOG</th>\n <td>Sam</td>\n <td>200</td>\n </tr>\n <tr>\n <th>MSFT</th>\n <td>Vanessa</td>\n <td>340</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 10
}
],
"source": [
"by_comp.max()"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Person Sales\n",
"Company \n",
"FB 2 2\n",
"GOOG 2 2\n",
"MSFT 2 2"
],
"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>Person</th>\n <th>Sales</th>\n </tr>\n <tr>\n <th>Company</th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>FB</th>\n <td>2</td>\n <td>2</td>\n </tr>\n <tr>\n <th>GOOG</th>\n <td>2</td>\n <td>2</td>\n </tr>\n <tr>\n <th>MSFT</th>\n <td>2</td>\n <td>2</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 11
}
],
"source": [
"by_comp.count()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Sales \n",
" count mean std min 25% 50% 75% max\n",
"Company \n",
"FB 2.0 296.5 75.660426 243.0 269.75 296.5 323.25 350.0\n",
"GOOG 2.0 160.0 56.568542 120.0 140.00 160.0 180.00 200.0\n",
"MSFT 2.0 232.0 152.735065 124.0 178.00 232.0 286.00 340.0"
],
"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 tr th {\n text-align: left;\n }\n\n .dataframe thead tr:last-of-type th {\n text-align: right;\n }\n</style>\n<table border=\"1\" class=\"dataframe\">\n <thead>\n <tr>\n <th></th>\n <th colspan=\"8\" halign=\"left\">Sales</th>\n </tr>\n <tr>\n <th></th>\n <th>count</th>\n <th>mean</th>\n <th>std</th>\n <th>min</th>\n <th>25%</th>\n <th>50%</th>\n <th>75%</th>\n <th>max</th>\n </tr>\n <tr>\n <th>Company</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>FB</th>\n <td>2.0</td>\n <td>296.5</td>\n <td>75.660426</td>\n <td>243.0</td>\n <td>269.75</td>\n <td>296.5</td>\n <td>323.25</td>\n <td>350.0</td>\n </tr>\n <tr>\n <th>GOOG</th>\n <td>2.0</td>\n <td>160.0</td>\n <td>56.568542</td>\n <td>120.0</td>\n <td>140.00</td>\n <td>160.0</td>\n <td>180.00</td>\n <td>200.0</td>\n </tr>\n <tr>\n <th>MSFT</th>\n <td>2.0</td>\n <td>232.0</td>\n <td>152.735065</td>\n <td>124.0</td>\n <td>178.00</td>\n <td>232.0</td>\n <td>286.00</td>\n <td>340.0</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 12
}
],
"source": [
"by_comp.describe()"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Company FB GOOG MSFT\n",
"Sales count 2.000000 2.000000 2.000000\n",
" mean 296.500000 160.000000 232.000000\n",
" std 75.660426 56.568542 152.735065\n",
" min 243.000000 120.000000 124.000000\n",
" 25% 269.750000 140.000000 178.000000\n",
" 50% 296.500000 160.000000 232.000000\n",
" 75% 323.250000 180.000000 286.000000\n",
" max 350.000000 200.000000 340.000000"
],
"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>Company</th>\n <th>FB</th>\n <th>GOOG</th>\n <th>MSFT</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th rowspan=\"8\" valign=\"top\">Sales</th>\n <th>count</th>\n <td>2.000000</td>\n <td>2.000000</td>\n <td>2.000000</td>\n </tr>\n <tr>\n <th>mean</th>\n <td>296.500000</td>\n <td>160.000000</td>\n <td>232.000000</td>\n </tr>\n <tr>\n <th>std</th>\n <td>75.660426</td>\n <td>56.568542</td>\n <td>152.735065</td>\n </tr>\n <tr>\n <th>min</th>\n <td>243.000000</td>\n <td>120.000000</td>\n <td>124.000000</td>\n </tr>\n <tr>\n <th>25%</th>\n <td>269.750000</td>\n <td>140.000000</td>\n <td>178.000000</td>\n </tr>\n <tr>\n <th>50%</th>\n <td>296.500000</td>\n <td>160.000000</td>\n <td>232.000000</td>\n </tr>\n <tr>\n <th>75%</th>\n <td>323.250000</td>\n <td>180.000000</td>\n <td>286.000000</td>\n </tr>\n <tr>\n <th>max</th>\n <td>350.000000</td>\n <td>200.000000</td>\n <td>340.000000</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 13
}
],
"source": [
"by_comp.describe().transpose()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Sales count 2.000000\n",
" mean 160.000000\n",
" std 56.568542\n",
" min 120.000000\n",
" 25% 140.000000\n",
" 50% 160.000000\n",
" 75% 180.000000\n",
" max 200.000000\n",
"Name: GOOG, dtype: float64"
]
},
"metadata": {},
"execution_count": 14
}
],
"source": [
"by_comp.describe().transpose()['GOOG']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!"
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.9 64-bit ('pyfinance': conda)",
"metadata": {
"interpreter": {
"hash": "e89404a230d8800c54ad520c7b67d1bd9bb833a07b37dd3e521a178a3dc34904"
}
}
},
"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.7.9-final"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,576 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Fusionner, Joindre et Concaténer\n",
"\n",
"Il y a 3 façons principales de combiner des DataFrames ensemble : Fusion, assemblage et concaténation. Dans ce notebook, nous discuterons de ces 3 méthodes avec des exemples.\n",
"\n",
"____"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Exemple DataFrames"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'],\n",
" 'B': ['B0', 'B1', 'B2', 'B3'],\n",
" 'C': ['C0', 'C1', 'C2', 'C3'],\n",
" 'D': ['D0', 'D1', 'D2', 'D3']},\n",
" index=[0, 1, 2, 3])"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"df2 = pd.DataFrame({'A': ['A4', 'A5', 'A6', 'A7'],\n",
" 'B': ['B4', 'B5', 'B6', 'B7'],\n",
" 'C': ['C4', 'C5', 'C6', 'C7'],\n",
" 'D': ['D4', 'D5', 'D6', 'D7']},\n",
" index=[4, 5, 6, 7]) "
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"df3 = pd.DataFrame({'A': ['A8', 'A9', 'A10', 'A11'],\n",
" 'B': ['B8', 'B9', 'B10', 'B11'],\n",
" 'C': ['C8', 'C9', 'C10', 'C11'],\n",
" 'D': ['D8', 'D9', 'D10', 'D11']},\n",
" index=[8, 9, 10, 11])"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C D\n",
"0 A0 B0 C0 D0\n",
"1 A1 B1 C1 D1\n",
"2 A2 B2 C2 D2\n",
"3 A3 B3 C3 D3"
],
"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 <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>A0</td>\n <td>B0</td>\n <td>C0</td>\n <td>D0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>A1</td>\n <td>B1</td>\n <td>C1</td>\n <td>D1</td>\n </tr>\n <tr>\n <th>2</th>\n <td>A2</td>\n <td>B2</td>\n <td>C2</td>\n <td>D2</td>\n </tr>\n <tr>\n <th>3</th>\n <td>A3</td>\n <td>B3</td>\n <td>C3</td>\n <td>D3</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 5
}
],
"source": [
"df1"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C D\n",
"4 A4 B4 C4 D4\n",
"5 A5 B5 C5 D5\n",
"6 A6 B6 C6 D6\n",
"7 A7 B7 C7 D7"
],
"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 <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>4</th>\n <td>A4</td>\n <td>B4</td>\n <td>C4</td>\n <td>D4</td>\n </tr>\n <tr>\n <th>5</th>\n <td>A5</td>\n <td>B5</td>\n <td>C5</td>\n <td>D5</td>\n </tr>\n <tr>\n <th>6</th>\n <td>A6</td>\n <td>B6</td>\n <td>C6</td>\n <td>D6</td>\n </tr>\n <tr>\n <th>7</th>\n <td>A7</td>\n <td>B7</td>\n <td>C7</td>\n <td>D7</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 6
}
],
"source": [
"df2"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C D\n",
"8 A8 B8 C8 D8\n",
"9 A9 B9 C9 D9\n",
"10 A10 B10 C10 D10\n",
"11 A11 B11 C11 D11"
],
"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 <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>8</th>\n <td>A8</td>\n <td>B8</td>\n <td>C8</td>\n <td>D8</td>\n </tr>\n <tr>\n <th>9</th>\n <td>A9</td>\n <td>B9</td>\n <td>C9</td>\n <td>D9</td>\n </tr>\n <tr>\n <th>10</th>\n <td>A10</td>\n <td>B10</td>\n <td>C10</td>\n <td>D10</td>\n </tr>\n <tr>\n <th>11</th>\n <td>A11</td>\n <td>B11</td>\n <td>C11</td>\n <td>D11</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 7
}
],
"source": [
"df3"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Concaténation\n",
"\n",
"La concaténation colle fondamentalement les DataFrames ensemble. Gardez à l'esprit que les dimensions doivent correspondre à l'axe sur lequel vous concaténez. Vous pouvez utiliser **pd.concat** et passer dans une liste de DataFrames à concaténer ensemble :"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C D\n",
"0 A0 B0 C0 D0\n",
"1 A1 B1 C1 D1\n",
"2 A2 B2 C2 D2\n",
"3 A3 B3 C3 D3\n",
"4 A4 B4 C4 D4\n",
"5 A5 B5 C5 D5\n",
"6 A6 B6 C6 D6\n",
"7 A7 B7 C7 D7\n",
"8 A8 B8 C8 D8\n",
"9 A9 B9 C9 D9\n",
"10 A10 B10 C10 D10\n",
"11 A11 B11 C11 D11"
],
"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 <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>A0</td>\n <td>B0</td>\n <td>C0</td>\n <td>D0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>A1</td>\n <td>B1</td>\n <td>C1</td>\n <td>D1</td>\n </tr>\n <tr>\n <th>2</th>\n <td>A2</td>\n <td>B2</td>\n <td>C2</td>\n <td>D2</td>\n </tr>\n <tr>\n <th>3</th>\n <td>A3</td>\n <td>B3</td>\n <td>C3</td>\n <td>D3</td>\n </tr>\n <tr>\n <th>4</th>\n <td>A4</td>\n <td>B4</td>\n <td>C4</td>\n <td>D4</td>\n </tr>\n <tr>\n <th>5</th>\n <td>A5</td>\n <td>B5</td>\n <td>C5</td>\n <td>D5</td>\n </tr>\n <tr>\n <th>6</th>\n <td>A6</td>\n <td>B6</td>\n <td>C6</td>\n <td>D6</td>\n </tr>\n <tr>\n <th>7</th>\n <td>A7</td>\n <td>B7</td>\n <td>C7</td>\n <td>D7</td>\n </tr>\n <tr>\n <th>8</th>\n <td>A8</td>\n <td>B8</td>\n <td>C8</td>\n <td>D8</td>\n </tr>\n <tr>\n <th>9</th>\n <td>A9</td>\n <td>B9</td>\n <td>C9</td>\n <td>D9</td>\n </tr>\n <tr>\n <th>10</th>\n <td>A10</td>\n <td>B10</td>\n <td>C10</td>\n <td>D10</td>\n </tr>\n <tr>\n <th>11</th>\n <td>A11</td>\n <td>B11</td>\n <td>C11</td>\n <td>D11</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 8
}
],
"source": [
"pd.concat([df1,df2,df3])"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C D A B C D A B C D\n",
"0 A0 B0 C0 D0 NaN NaN NaN NaN NaN NaN NaN NaN\n",
"1 A1 B1 C1 D1 NaN NaN NaN NaN NaN NaN NaN NaN\n",
"2 A2 B2 C2 D2 NaN NaN NaN NaN NaN NaN NaN NaN\n",
"3 A3 B3 C3 D3 NaN NaN NaN NaN NaN NaN NaN NaN\n",
"4 NaN NaN NaN NaN A4 B4 C4 D4 NaN NaN NaN NaN\n",
"5 NaN NaN NaN NaN A5 B5 C5 D5 NaN NaN NaN NaN\n",
"6 NaN NaN NaN NaN A6 B6 C6 D6 NaN NaN NaN NaN\n",
"7 NaN NaN NaN NaN A7 B7 C7 D7 NaN NaN NaN NaN\n",
"8 NaN NaN NaN NaN NaN NaN NaN NaN A8 B8 C8 D8\n",
"9 NaN NaN NaN NaN NaN NaN NaN NaN A9 B9 C9 D9\n",
"10 NaN NaN NaN NaN NaN NaN NaN NaN A10 B10 C10 D10\n",
"11 NaN NaN NaN NaN NaN NaN NaN NaN A11 B11 C11 D11"
],
"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 <th>D</th>\n <th>A</th>\n <th>B</th>\n <th>C</th>\n <th>D</th>\n <th>A</th>\n <th>B</th>\n <th>C</th>\n <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>A0</td>\n <td>B0</td>\n <td>C0</td>\n <td>D0</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>1</th>\n <td>A1</td>\n <td>B1</td>\n <td>C1</td>\n <td>D1</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>2</th>\n <td>A2</td>\n <td>B2</td>\n <td>C2</td>\n <td>D2</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>3</th>\n <td>A3</td>\n <td>B3</td>\n <td>C3</td>\n <td>D3</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>4</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>A4</td>\n <td>B4</td>\n <td>C4</td>\n <td>D4</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>5</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>A5</td>\n <td>B5</td>\n <td>C5</td>\n <td>D5</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>6</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>A6</td>\n <td>B6</td>\n <td>C6</td>\n <td>D6</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>7</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>A7</td>\n <td>B7</td>\n <td>C7</td>\n <td>D7</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>8</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>A8</td>\n <td>B8</td>\n <td>C8</td>\n <td>D8</td>\n </tr>\n <tr>\n <th>9</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>A9</td>\n <td>B9</td>\n <td>C9</td>\n <td>D9</td>\n </tr>\n <tr>\n <th>10</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>A10</td>\n <td>B10</td>\n <td>C10</td>\n <td>D10</td>\n </tr>\n <tr>\n <th>11</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>A11</td>\n <td>B11</td>\n <td>C11</td>\n <td>D11</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 9
}
],
"source": [
"pd.concat([df1,df2,df3],axis=1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"_____\n",
"## Exemple DataFrames"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"left = pd.DataFrame({'key': ['K0', 'K1', 'K2', 'K3'],\n",
" 'A': ['A0', 'A1', 'A2', 'A3'],\n",
" 'B': ['B0', 'B1', 'B2', 'B3']})\n",
" \n",
"right = pd.DataFrame({'key': ['K0', 'K1', 'K2', 'K3'],\n",
" 'C': ['C0', 'C1', 'C2', 'C3'],\n",
" 'D': ['D0', 'D1', 'D2', 'D3']}) "
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" key A B\n",
"0 K0 A0 B0\n",
"1 K1 A1 B1\n",
"2 K2 A2 B2\n",
"3 K3 A3 B3"
],
"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>key</th>\n <th>A</th>\n <th>B</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>K0</td>\n <td>A0</td>\n <td>B0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>K1</td>\n <td>A1</td>\n <td>B1</td>\n </tr>\n <tr>\n <th>2</th>\n <td>K2</td>\n <td>A2</td>\n <td>B2</td>\n </tr>\n <tr>\n <th>3</th>\n <td>K3</td>\n <td>A3</td>\n <td>B3</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 11
}
],
"source": [
"left"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" key C D\n",
"0 K0 C0 D0\n",
"1 K1 C1 D1\n",
"2 K2 C2 D2\n",
"3 K3 C3 D3"
],
"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>key</th>\n <th>C</th>\n <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>K0</td>\n <td>C0</td>\n <td>D0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>K1</td>\n <td>C1</td>\n <td>D1</td>\n </tr>\n <tr>\n <th>2</th>\n <td>K2</td>\n <td>C2</td>\n <td>D2</td>\n </tr>\n <tr>\n <th>3</th>\n <td>K3</td>\n <td>C3</td>\n <td>D3</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 12
}
],
"source": [
"right"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Fusion\n",
"\n",
"La fonction **merge** vous permet de fusionner des DataFrames ensemble en utilisant une logique similaire à celle de la fusion de Tables SQL. Par exemple :"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" key A B C D\n",
"0 K0 A0 B0 C0 D0\n",
"1 K1 A1 B1 C1 D1\n",
"2 K2 A2 B2 C2 D2\n",
"3 K3 A3 B3 C3 D3"
],
"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>key</th>\n <th>A</th>\n <th>B</th>\n <th>C</th>\n <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>K0</td>\n <td>A0</td>\n <td>B0</td>\n <td>C0</td>\n <td>D0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>K1</td>\n <td>A1</td>\n <td>B1</td>\n <td>C1</td>\n <td>D1</td>\n </tr>\n <tr>\n <th>2</th>\n <td>K2</td>\n <td>A2</td>\n <td>B2</td>\n <td>C2</td>\n <td>D2</td>\n </tr>\n <tr>\n <th>3</th>\n <td>K3</td>\n <td>A3</td>\n <td>B3</td>\n <td>C3</td>\n <td>D3</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 13
}
],
"source": [
"pd.merge(left,right,how='inner',on='key')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Exemple plus compliqué :"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"left = pd.DataFrame({'key1': ['K0', 'K0', 'K1', 'K2'],\n",
" 'key2': ['K0', 'K1', 'K0', 'K1'],\n",
" 'A': ['A0', 'A1', 'A2', 'A3'],\n",
" 'B': ['B0', 'B1', 'B2', 'B3']})\n",
" \n",
"right = pd.DataFrame({'key1': ['K0', 'K1', 'K1', 'K2'],\n",
" 'key2': ['K0', 'K0', 'K0', 'K0'],\n",
" 'C': ['C0', 'C1', 'C2', 'C3'],\n",
" 'D': ['D0', 'D1', 'D2', 'D3']})"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" key1 key2 A B C D\n",
"0 K0 K0 A0 B0 C0 D0\n",
"1 K1 K0 A2 B2 C1 D1\n",
"2 K1 K0 A2 B2 C2 D2"
],
"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>key1</th>\n <th>key2</th>\n <th>A</th>\n <th>B</th>\n <th>C</th>\n <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>K0</td>\n <td>K0</td>\n <td>A0</td>\n <td>B0</td>\n <td>C0</td>\n <td>D0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>K1</td>\n <td>K0</td>\n <td>A2</td>\n <td>B2</td>\n <td>C1</td>\n <td>D1</td>\n </tr>\n <tr>\n <th>2</th>\n <td>K1</td>\n <td>K0</td>\n <td>A2</td>\n <td>B2</td>\n <td>C2</td>\n <td>D2</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 15
}
],
"source": [
"pd.merge(left, right, on=['key1', 'key2'])"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" key1 key2 A B C D\n",
"0 K0 K0 A0 B0 C0 D0\n",
"1 K0 K1 A1 B1 NaN NaN\n",
"2 K1 K0 A2 B2 C1 D1\n",
"3 K1 K0 A2 B2 C2 D2\n",
"4 K2 K1 A3 B3 NaN NaN\n",
"5 K2 K0 NaN NaN C3 D3"
],
"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>key1</th>\n <th>key2</th>\n <th>A</th>\n <th>B</th>\n <th>C</th>\n <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>K0</td>\n <td>K0</td>\n <td>A0</td>\n <td>B0</td>\n <td>C0</td>\n <td>D0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>K0</td>\n <td>K1</td>\n <td>A1</td>\n <td>B1</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>2</th>\n <td>K1</td>\n <td>K0</td>\n <td>A2</td>\n <td>B2</td>\n <td>C1</td>\n <td>D1</td>\n </tr>\n <tr>\n <th>3</th>\n <td>K1</td>\n <td>K0</td>\n <td>A2</td>\n <td>B2</td>\n <td>C2</td>\n <td>D2</td>\n </tr>\n <tr>\n <th>4</th>\n <td>K2</td>\n <td>K1</td>\n <td>A3</td>\n <td>B3</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>5</th>\n <td>K2</td>\n <td>K0</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>C3</td>\n <td>D3</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 16
}
],
"source": [
"pd.merge(left, right, how='outer', on=['key1', 'key2'])"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" key1 key2 A B C D\n",
"0 K0 K0 A0 B0 C0 D0\n",
"1 K1 K0 A2 B2 C1 D1\n",
"2 K1 K0 A2 B2 C2 D2\n",
"3 K2 K0 NaN NaN C3 D3"
],
"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>key1</th>\n <th>key2</th>\n <th>A</th>\n <th>B</th>\n <th>C</th>\n <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>K0</td>\n <td>K0</td>\n <td>A0</td>\n <td>B0</td>\n <td>C0</td>\n <td>D0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>K1</td>\n <td>K0</td>\n <td>A2</td>\n <td>B2</td>\n <td>C1</td>\n <td>D1</td>\n </tr>\n <tr>\n <th>2</th>\n <td>K1</td>\n <td>K0</td>\n <td>A2</td>\n <td>B2</td>\n <td>C2</td>\n <td>D2</td>\n </tr>\n <tr>\n <th>3</th>\n <td>K2</td>\n <td>K0</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>C3</td>\n <td>D3</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 17
}
],
"source": [
"pd.merge(left, right, how='right', on=['key1', 'key2'])"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" key1 key2 A B C D\n",
"0 K0 K0 A0 B0 C0 D0\n",
"1 K0 K1 A1 B1 NaN NaN\n",
"2 K1 K0 A2 B2 C1 D1\n",
"3 K1 K0 A2 B2 C2 D2\n",
"4 K2 K1 A3 B3 NaN NaN"
],
"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>key1</th>\n <th>key2</th>\n <th>A</th>\n <th>B</th>\n <th>C</th>\n <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>K0</td>\n <td>K0</td>\n <td>A0</td>\n <td>B0</td>\n <td>C0</td>\n <td>D0</td>\n </tr>\n <tr>\n <th>1</th>\n <td>K0</td>\n <td>K1</td>\n <td>A1</td>\n <td>B1</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>2</th>\n <td>K1</td>\n <td>K0</td>\n <td>A2</td>\n <td>B2</td>\n <td>C1</td>\n <td>D1</td>\n </tr>\n <tr>\n <th>3</th>\n <td>K1</td>\n <td>K0</td>\n <td>A2</td>\n <td>B2</td>\n <td>C2</td>\n <td>D2</td>\n </tr>\n <tr>\n <th>4</th>\n <td>K2</td>\n <td>K1</td>\n <td>A3</td>\n <td>B3</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 18
}
],
"source": [
"pd.merge(left, right, how='left', on=['key1', 'key2'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Assemblage\n",
"Join est une méthode pratique pour combiner les colonnes de deux DataFrames potentiellement indexées différemment résultant en un seul DataFrame."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"left = pd.DataFrame({'A': ['A0', 'A1', 'A2'],\n",
" 'B': ['B0', 'B1', 'B2']},\n",
" index=['K0', 'K1', 'K2']) \n",
"\n",
"right = pd.DataFrame({'C': ['C0', 'C2', 'C3'],\n",
" 'D': ['D0', 'D2', 'D3']},\n",
" index=['K0', 'K2', 'K3'])"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C D\n",
"K0 A0 B0 C0 D0\n",
"K1 A1 B1 NaN NaN\n",
"K2 A2 B2 C2 D2"
],
"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 <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>K0</th>\n <td>A0</td>\n <td>B0</td>\n <td>C0</td>\n <td>D0</td>\n </tr>\n <tr>\n <th>K1</th>\n <td>A1</td>\n <td>B1</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>K2</th>\n <td>A2</td>\n <td>B2</td>\n <td>C2</td>\n <td>D2</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 20
}
],
"source": [
"left.join(right)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C D\n",
"K0 A0 B0 C0 D0\n",
"K1 A1 B1 NaN NaN\n",
"K2 A2 B2 C2 D2\n",
"K3 NaN NaN C3 D3"
],
"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 <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>K0</th>\n <td>A0</td>\n <td>B0</td>\n <td>C0</td>\n <td>D0</td>\n </tr>\n <tr>\n <th>K1</th>\n <td>A1</td>\n <td>B1</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>K2</th>\n <td>A2</td>\n <td>B2</td>\n <td>C2</td>\n <td>D2</td>\n </tr>\n <tr>\n <th>K3</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>C3</td>\n <td>D3</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 21
}
],
"source": [
"left.join(right, how='outer')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!"
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.9 64-bit ('pyfinance': conda)",
"metadata": {
"interpreter": {
"hash": "e89404a230d8800c54ad520c7b67d1bd9bb833a07b37dd3e521a178a3dc34904"
}
}
},
"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.7.9-final"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,614 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"# Opérations\n",
"\n",
"Il y a beaucoup d'opérations avec pandas qui vous seront vraiment utiles, mais elles n'entraient dans aucune case. Montrons-les ici dans ce notebook:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" col1 col2 col3\n",
"0 1 444 abc\n",
"1 2 555 def\n",
"2 3 666 ghi\n",
"3 4 444 xyz"
],
"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>col1</th>\n <th>col2</th>\n <th>col3</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n <td>444</td>\n <td>abc</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>555</td>\n <td>def</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>666</td>\n <td>ghi</td>\n </tr>\n <tr>\n <th>3</th>\n <td>4</td>\n <td>444</td>\n <td>xyz</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 1
}
],
"source": [
"import pandas as pd\n",
"df = pd.DataFrame({'col1':[1,2,3,4],'col2':[444,555,666,444],'col3':['abc','def','ghi','xyz']})\n",
"df.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Informations sur les valeurs uniques"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array([444, 555, 666], dtype=int64)"
]
},
"metadata": {},
"execution_count": 2
}
],
"source": [
"df['col2'].unique()"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"3"
]
},
"metadata": {},
"execution_count": 3
}
],
"source": [
"df['col2'].nunique()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"444 2\n",
"555 1\n",
"666 1\n",
"Name: col2, dtype: int64"
]
},
"metadata": {},
"execution_count": 4
}
],
"source": [
"df['col2'].value_counts()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Sélection des données"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Sélection à partir d'un DataFrame en utilisant des critères \n",
"# de plusieurs colonnes\n",
"newdf = df[(df['col1']>2) & (df['col2']==444)]"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" col1 col2 col3\n",
"3 4 444 xyz"
],
"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>col1</th>\n <th>col2</th>\n <th>col3</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>3</th>\n <td>4</td>\n <td>444</td>\n <td>xyz</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 6
}
],
"source": [
"newdf"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Appliquer des Fonctions"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def times2(x):\n",
" return x*2"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0 2\n",
"1 4\n",
"2 6\n",
"3 8\n",
"Name: col1, dtype: int64"
]
},
"metadata": {},
"execution_count": 8
}
],
"source": [
"df['col1'].apply(times2)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0 3\n",
"1 3\n",
"2 3\n",
"3 3\n",
"Name: col3, dtype: int64"
]
},
"metadata": {},
"execution_count": 9
}
],
"source": [
"df['col3'].apply(len)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"10"
]
},
"metadata": {},
"execution_count": 10
}
],
"source": [
"df['col1'].sum()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Suppression définitive d'une colonne**"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"del df['col1']"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" col2 col3\n",
"0 444 abc\n",
"1 555 def\n",
"2 666 ghi\n",
"3 444 xyz"
],
"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>col2</th>\n <th>col3</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>444</td>\n <td>abc</td>\n </tr>\n <tr>\n <th>1</th>\n <td>555</td>\n <td>def</td>\n </tr>\n <tr>\n <th>2</th>\n <td>666</td>\n <td>ghi</td>\n </tr>\n <tr>\n <th>3</th>\n <td>444</td>\n <td>xyz</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 12
}
],
"source": [
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Obtenir les noms des colonnes et des index :**"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Index(['col2', 'col3'], dtype='object')"
]
},
"metadata": {},
"execution_count": 13
}
],
"source": [
"df.columns"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"RangeIndex(start=0, stop=4, step=1)"
]
},
"metadata": {},
"execution_count": 14
}
],
"source": [
"df.index"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Trier un DataFrame :**"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" col2 col3\n",
"0 444 abc\n",
"1 555 def\n",
"2 666 ghi\n",
"3 444 xyz"
],
"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>col2</th>\n <th>col3</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>444</td>\n <td>abc</td>\n </tr>\n <tr>\n <th>1</th>\n <td>555</td>\n <td>def</td>\n </tr>\n <tr>\n <th>2</th>\n <td>666</td>\n <td>ghi</td>\n </tr>\n <tr>\n <th>3</th>\n <td>444</td>\n <td>xyz</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 15
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" col2 col3\n",
"0 444 abc\n",
"3 444 xyz\n",
"1 555 def\n",
"2 666 ghi"
],
"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>col2</th>\n <th>col3</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>444</td>\n <td>abc</td>\n </tr>\n <tr>\n <th>3</th>\n <td>444</td>\n <td>xyz</td>\n </tr>\n <tr>\n <th>1</th>\n <td>555</td>\n <td>def</td>\n </tr>\n <tr>\n <th>2</th>\n <td>666</td>\n <td>ghi</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 16
}
],
"source": [
"df.sort_values(by='col2') #inplace=False par défaut"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Recherche de valeurs nulles ou vérification des valeurs nulles**"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" col2 col3\n",
"0 False False\n",
"1 False False\n",
"2 False False\n",
"3 False False"
],
"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>col2</th>\n <th>col3</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>False</td>\n <td>False</td>\n </tr>\n <tr>\n <th>1</th>\n <td>False</td>\n <td>False</td>\n </tr>\n <tr>\n <th>2</th>\n <td>False</td>\n <td>False</td>\n </tr>\n <tr>\n <th>3</th>\n <td>False</td>\n <td>False</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 17
}
],
"source": [
"df.isnull()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" col2 col3\n",
"0 444 abc\n",
"1 555 def\n",
"2 666 ghi\n",
"3 444 xyz"
],
"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>col2</th>\n <th>col3</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>444</td>\n <td>abc</td>\n </tr>\n <tr>\n <th>1</th>\n <td>555</td>\n <td>def</td>\n </tr>\n <tr>\n <th>2</th>\n <td>666</td>\n <td>ghi</td>\n </tr>\n <tr>\n <th>3</th>\n <td>444</td>\n <td>xyz</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 18
}
],
"source": [
"# Supprimer les lignes contenant des valeurs NaN\n",
"df.dropna()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Remplir les valeurs NaN avec autre chose :**"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" col1 col2 col3\n",
"0 1.0 NaN abc\n",
"1 2.0 555.0 def\n",
"2 3.0 666.0 ghi\n",
"3 NaN 444.0 xyz"
],
"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>col1</th>\n <th>col2</th>\n <th>col3</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1.0</td>\n <td>NaN</td>\n <td>abc</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2.0</td>\n <td>555.0</td>\n <td>def</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3.0</td>\n <td>666.0</td>\n <td>ghi</td>\n </tr>\n <tr>\n <th>3</th>\n <td>NaN</td>\n <td>444.0</td>\n <td>xyz</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 20
}
],
"source": [
"df = pd.DataFrame({'col1':[1,2,3,np.nan],\n",
" 'col2':[np.nan,555,666,444],\n",
" 'col3':['abc','def','ghi','xyz']})\n",
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" col1 col2 col3\n",
"0 1 FILL abc\n",
"1 2 555 def\n",
"2 3 666 ghi\n",
"3 FILL 444 xyz"
],
"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>col1</th>\n <th>col2</th>\n <th>col3</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>1</td>\n <td>FILL</td>\n <td>abc</td>\n </tr>\n <tr>\n <th>1</th>\n <td>2</td>\n <td>555</td>\n <td>def</td>\n </tr>\n <tr>\n <th>2</th>\n <td>3</td>\n <td>666</td>\n <td>ghi</td>\n </tr>\n <tr>\n <th>3</th>\n <td>FILL</td>\n <td>444</td>\n <td>xyz</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 21
}
],
"source": [
"df.fillna('FILL')"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"data = {'A':['foo','foo','foo','bar','bar','bar'],\n",
" 'B':['one','one','two','two','one','one'],\n",
" 'C':['x','y','x','y','x','y'],\n",
" 'D':[1,3,2,5,4,1]}\n",
"\n",
"df = pd.DataFrame(data)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B C D\n",
"0 foo one x 1\n",
"1 foo one y 3\n",
"2 foo two x 2\n",
"3 bar two y 5\n",
"4 bar one x 4\n",
"5 bar one y 1"
],
"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 <th>D</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>foo</td>\n <td>one</td>\n <td>x</td>\n <td>1</td>\n </tr>\n <tr>\n <th>1</th>\n <td>foo</td>\n <td>one</td>\n <td>y</td>\n <td>3</td>\n </tr>\n <tr>\n <th>2</th>\n <td>foo</td>\n <td>two</td>\n <td>x</td>\n <td>2</td>\n </tr>\n <tr>\n <th>3</th>\n <td>bar</td>\n <td>two</td>\n <td>y</td>\n <td>5</td>\n </tr>\n <tr>\n <th>4</th>\n <td>bar</td>\n <td>one</td>\n <td>x</td>\n <td>4</td>\n </tr>\n <tr>\n <th>5</th>\n <td>bar</td>\n <td>one</td>\n <td>y</td>\n <td>1</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 23
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"C x y\n",
"A B \n",
"bar one 4.0 1.0\n",
" two NaN 5.0\n",
"foo one 1.0 3.0\n",
" two 2.0 NaN"
],
"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>C</th>\n <th>x</th>\n <th>y</th>\n </tr>\n <tr>\n <th>A</th>\n <th>B</th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th rowspan=\"2\" valign=\"top\">bar</th>\n <th>one</th>\n <td>4.0</td>\n <td>1.0</td>\n </tr>\n <tr>\n <th>two</th>\n <td>NaN</td>\n <td>5.0</td>\n </tr>\n <tr>\n <th rowspan=\"2\" valign=\"top\">foo</th>\n <th>one</th>\n <td>1.0</td>\n <td>3.0</td>\n </tr>\n <tr>\n <th>two</th>\n <td>2.0</td>\n <td>NaN</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 24
}
],
"source": [
"df.pivot_table(values='D',index=['A', 'B'],columns=['C'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!"
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.9 64-bit ('pyfinance': conda)",
"metadata": {
"interpreter": {
"hash": "e89404a230d8800c54ad520c7b67d1bd9bb833a07b37dd3e521a178a3dc34904"
}
}
},
"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.7.9-final"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,261 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Nous nous contenterons soit de lire les fichiers csv directement, soit d'utiliser pandas-datareader ou quandl. Considérez ce notebook comme un bref aperçu de ce qui est possible de faire avec pandas (nous ne travaillerons pas avec des fichiers SQL ou excel dans ce cours).**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Data Input et Output\n",
"\n",
"Ce notebook est le code de référence pour obtenir des entrées et des sorties, pandas peut lire une variété de types de fichiers en utilisant ses méthodes pd.read_. Jetons un coup d'oeil aux types de données les plus courants:"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## CSV\n",
"\n",
"### CSV Input"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" a b c d\n",
"0 0 1 2 3\n",
"1 4 5 6 7\n",
"2 8 9 10 11\n",
"3 12 13 14 15"
],
"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 <th>d</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>0</td>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n </tr>\n <tr>\n <th>1</th>\n <td>4</td>\n <td>5</td>\n <td>6</td>\n <td>7</td>\n </tr>\n <tr>\n <th>2</th>\n <td>8</td>\n <td>9</td>\n <td>10</td>\n <td>11</td>\n </tr>\n <tr>\n <th>3</th>\n <td>12</td>\n <td>13</td>\n <td>14</td>\n <td>15</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 2
}
],
"source": [
"df = pd.read_csv('example.csv')\n",
"df"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### CSV Output"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"df.to_csv('example',index=False)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Excel\n",
"Pandas peut lire et écrire des fichiers excel, gardez à l'esprit que ceci n'importe que des données. Pas de formules ni d'images, le fait d'avoir des images ou des macros peut provoquer le crash de cette méthode read_excel. "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Excel Input"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Unnamed: 0 a b c d\n",
"0 0 0 1 2 3\n",
"1 1 4 5 6 7\n",
"2 2 8 9 10 11\n",
"3 3 12 13 14 15"
],
"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>Unnamed: 0</th>\n <th>a</th>\n <th>b</th>\n <th>c</th>\n <th>d</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>0</td>\n <td>0</td>\n <td>1</td>\n <td>2</td>\n <td>3</td>\n </tr>\n <tr>\n <th>1</th>\n <td>1</td>\n <td>4</td>\n <td>5</td>\n <td>6</td>\n <td>7</td>\n </tr>\n <tr>\n <th>2</th>\n <td>2</td>\n <td>8</td>\n <td>9</td>\n <td>10</td>\n <td>11</td>\n </tr>\n <tr>\n <th>3</th>\n <td>3</td>\n <td>12</td>\n <td>13</td>\n <td>14</td>\n <td>15</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 4
}
],
"source": [
"pd.read_excel('Excel_Sample.xlsx',sheet_name='Sheet1')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Excel Output"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"df.to_excel('Excel_Sample.xlsx',sheet_name='Sheet1')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## HTML\n",
"\n",
"Vous aurez besoin d'installer htmllib5, lxml et BeautifulSoup4. Dans votre terminal/command prompt tapez:\n",
"\n",
" conda install lxml\n",
" conda install html5lib\n",
" conda install BeautifulSoup4\n",
"\n",
"Puis redémarrez Jupyter Notebook.\n",
"(ou utilisez pip install si vous n'utilisez pas la distribution Anaconda)\n",
"\n",
"Pandas peut lire du HTML. Par exemple:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### HTML Input\n",
"\n",
"La fonction pandas read_html lit les balises table d'une page web et retourne une liste d'objets DataFrame:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_html('http://www.fdic.gov/bank/individual/failed/banklist.html')"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Bank Name City ST CERT \\\n",
"0 Almena State Bank Almena KS 15426 \n",
"1 First City Bank of Florida Fort Walton Beach FL 16748 \n",
"2 The First State Bank Barboursville WV 14361 \n",
"3 Ericson State Bank Ericson NE 18265 \n",
"4 City National Bank of New Jersey Newark NJ 21111 \n",
".. ... ... .. ... \n",
"558 Superior Bank, FSB Hinsdale IL 32646 \n",
"559 Malta National Bank Malta OH 6629 \n",
"560 First Alliance Bank & Trust Co. Manchester NH 34264 \n",
"561 National State Bank of Metropolis Metropolis IL 3815 \n",
"562 Bank of Honolulu Honolulu HI 21029 \n",
"\n",
" Acquiring Institution Closing Date \n",
"0 Equity Bank October 23, 2020 \n",
"1 United Fidelity Bank, fsb October 16, 2020 \n",
"2 MVB Bank, Inc. April 3, 2020 \n",
"3 Farmers and Merchants Bank February 14, 2020 \n",
"4 Industrial Bank November 1, 2019 \n",
".. ... ... \n",
"558 Superior Federal, FSB July 27, 2001 \n",
"559 North Valley Bank May 3, 2001 \n",
"560 Southern New Hampshire Bank & Trust February 2, 2001 \n",
"561 Banterra Bank of Marion December 14, 2000 \n",
"562 Bank of the Orient October 13, 2000 \n",
"\n",
"[563 rows x 6 columns]"
],
"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>Bank Name</th>\n <th>City</th>\n <th>ST</th>\n <th>CERT</th>\n <th>Acquiring Institution</th>\n <th>Closing Date</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Almena State Bank</td>\n <td>Almena</td>\n <td>KS</td>\n <td>15426</td>\n <td>Equity Bank</td>\n <td>October 23, 2020</td>\n </tr>\n <tr>\n <th>1</th>\n <td>First City Bank of Florida</td>\n <td>Fort Walton Beach</td>\n <td>FL</td>\n <td>16748</td>\n <td>United Fidelity Bank, fsb</td>\n <td>October 16, 2020</td>\n </tr>\n <tr>\n <th>2</th>\n <td>The First State Bank</td>\n <td>Barboursville</td>\n <td>WV</td>\n <td>14361</td>\n <td>MVB Bank, Inc.</td>\n <td>April 3, 2020</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Ericson State Bank</td>\n <td>Ericson</td>\n <td>NE</td>\n <td>18265</td>\n <td>Farmers and Merchants Bank</td>\n <td>February 14, 2020</td>\n </tr>\n <tr>\n <th>4</th>\n <td>City National Bank of New Jersey</td>\n <td>Newark</td>\n <td>NJ</td>\n <td>21111</td>\n <td>Industrial Bank</td>\n <td>November 1, 2019</td>\n </tr>\n <tr>\n <th>...</th>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n <td>...</td>\n </tr>\n <tr>\n <th>558</th>\n <td>Superior Bank, FSB</td>\n <td>Hinsdale</td>\n <td>IL</td>\n <td>32646</td>\n <td>Superior Federal, FSB</td>\n <td>July 27, 2001</td>\n </tr>\n <tr>\n <th>559</th>\n <td>Malta National Bank</td>\n <td>Malta</td>\n <td>OH</td>\n <td>6629</td>\n <td>North Valley Bank</td>\n <td>May 3, 2001</td>\n </tr>\n <tr>\n <th>560</th>\n <td>First Alliance Bank &amp; Trust Co.</td>\n <td>Manchester</td>\n <td>NH</td>\n <td>34264</td>\n <td>Southern New Hampshire Bank &amp; Trust</td>\n <td>February 2, 2001</td>\n </tr>\n <tr>\n <th>561</th>\n <td>National State Bank of Metropolis</td>\n <td>Metropolis</td>\n <td>IL</td>\n <td>3815</td>\n <td>Banterra Bank of Marion</td>\n <td>December 14, 2000</td>\n </tr>\n <tr>\n <th>562</th>\n <td>Bank of Honolulu</td>\n <td>Honolulu</td>\n <td>HI</td>\n <td>21029</td>\n <td>Bank of the Orient</td>\n <td>October 13, 2000</td>\n </tr>\n </tbody>\n</table>\n<p>563 rows × 6 columns</p>\n</div>"
},
"metadata": {},
"execution_count": 7
}
],
"source": [
"df[0]"
]
},
{
"cell_type": "markdown",
"metadata": {
"collapsed": true
},
"source": [
"____"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!"
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.9 64-bit ('pyfinance': conda)",
"metadata": {
"interpreter": {
"hash": "e89404a230d8800c54ad520c7b67d1bd9bb833a07b37dd3e521a178a3dc34904"
}
}
},
"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.7.9-final"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

BIN
03-Pandas/Excel_Sample.xlsx Normal file

Binary file not shown.

Binary file not shown.

5
03-Pandas/My_output Normal file
View File

@ -0,0 +1,5 @@
a,b,c,d
0,1,2,3
4,5,6,7
8,9,10,11
12,13,14,15

View File

@ -0,0 +1,780 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pandas Exercices"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Il est temps de tester vos nouvelles compétences en pandas ! Utilisez le fichier csv de ce dossier pour effectuer les tâches en gras ci-dessous!\n",
"\n",
"#### NOTE : TOUTES LES TÂCHES DOIVENT ÊTRE EFFECTUÉES SUR UNE SEULE LIGNE AVEC DU CODE PANDAS. BLOQUé(e) ? PAS DE PROBLÈME ! CONSULTEZ LE NOTEBOOK AVEC LES SOLUTIONS ! "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Importer pandas et lire le fichier banklist.csv dans un dataframe nommé banks. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"banks = pd.read_csv('banklist.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Afficher les 5 premières lignes du dataframe"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Bank Name</th>\n",
" <th>City</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Fayette County Bank</td>\n",
" <td>Saint Elmo</td>\n",
" <td>IL</td>\n",
" <td>1802</td>\n",
" <td>United Fidelity Bank, fsb</td>\n",
" <td>26-May-17</td>\n",
" <td>1-Jun-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Guaranty Bank, (d/b/a BestBank in Georgia &amp; Mi...</td>\n",
" <td>Milwaukee</td>\n",
" <td>WI</td>\n",
" <td>30003</td>\n",
" <td>First-Citizens Bank &amp; Trust Company</td>\n",
" <td>5-May-17</td>\n",
" <td>1-Jun-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>First NBC Bank</td>\n",
" <td>New Orleans</td>\n",
" <td>LA</td>\n",
" <td>58302</td>\n",
" <td>Whitney Bank</td>\n",
" <td>28-Apr-17</td>\n",
" <td>23-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Proficio Bank</td>\n",
" <td>Cottonwood Heights</td>\n",
" <td>UT</td>\n",
" <td>35495</td>\n",
" <td>Cache Valley Bank</td>\n",
" <td>3-Mar-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Seaway Bank and Trust Company</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>19328</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>27-Jan-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name City ST \\\n",
"0 Fayette County Bank Saint Elmo IL \n",
"1 Guaranty Bank, (d/b/a BestBank in Georgia & Mi... Milwaukee WI \n",
"2 First NBC Bank New Orleans LA \n",
"3 Proficio Bank Cottonwood Heights UT \n",
"4 Seaway Bank and Trust Company Chicago IL \n",
"\n",
" CERT Acquiring Institution Closing Date Updated Date \n",
"0 1802 United Fidelity Bank, fsb 26-May-17 1-Jun-17 \n",
"1 30003 First-Citizens Bank & Trust Company 5-May-17 1-Jun-17 \n",
"2 58302 Whitney Bank 28-Apr-17 23-May-17 \n",
"3 35495 Cache Valley Bank 3-Mar-17 18-May-17 \n",
"4 19328 State Bank of Texas 27-Jan-17 18-May-17 "
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les noms de colonne?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Bank Name', 'City', 'ST', 'CERT', 'Acquiring Institution',\n",
" 'Closing Date', 'Updated Date'],\n",
" dtype='object')"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien d'états (ST) sont représentés dans cet ensemble de données?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"44"
]
},
"execution_count": 33,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Obtenir une liste ou tableau de tous les états du dataset."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['IL', 'WI', 'LA', 'UT', 'NJ', 'AR', 'GA', 'PA', 'TN', 'WA', 'CO',\n",
" 'PR', 'FL', 'MN', 'CA', 'MD', 'OK', 'OH', 'SC', 'VA', 'ID', 'TX',\n",
" 'CT', 'AZ', 'NV', 'NC', 'KY', 'MO', 'KS', 'AL', 'MI', 'IN', 'IA',\n",
" 'NE', 'MS', 'NM', 'OR', 'NY', 'MA', 'SD', 'WY', 'WV', 'NH', 'HI'], dtype=object)"
]
},
"execution_count": 32,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les 5 états avec le plus de banques en faillite?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true,
"scrolled": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"ST\n",
"GA 93\n",
"FL 75\n",
"IL 67\n",
"CA 41\n",
"MN 23\n",
"Name: Bank Name, dtype: int64"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les 5 principaux établissements acquéreurs?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"No Acquirer 31\n",
"State Bank and Trust Company 12\n",
"First-Citizens Bank & Trust Company 11\n",
"Ameris Bank 10\n",
"U.S. Bank N.A. 9\n",
"Name: Acquiring Institution, dtype: int64"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de banques State Bank of Texas a-t-elle acquises ? Combien d'entre elles étaient au Texas ?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Bank Name</th>\n",
" <th>City</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Seaway Bank and Trust Company</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>19328</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>27-Jan-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>The National Republic Bank of Chicago</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>916</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>24-Oct-14</td>\n",
" <td>6-Jan-16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>450</th>\n",
" <td>Millennium State Bank of Texas</td>\n",
" <td>Dallas</td>\n",
" <td>TX</td>\n",
" <td>57667</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>2-Jul-09</td>\n",
" <td>26-Oct-12</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name City ST CERT \\\n",
"4 Seaway Bank and Trust Company Chicago IL 19328 \n",
"21 The National Republic Bank of Chicago Chicago IL 916 \n",
"450 Millennium State Bank of Texas Dallas TX 57667 \n",
"\n",
" Acquiring Institution Closing Date Updated Date \n",
"4 State Bank of Texas 27-Jan-17 18-May-17 \n",
"21 State Bank of Texas 24-Oct-14 6-Jan-16 \n",
"450 State Bank of Texas 2-Jul-09 26-Oct-12 "
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quelle est la ville la plus fréquente en Californie pour qu'une banque fasse faillite ?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Bank Name</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" <tr>\n",
" <th>City</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Los Angeles</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name ST CERT Acquiring Institution Closing Date \\\n",
"City \n",
"Los Angeles 4 4 4 4 4 \n",
"\n",
" Updated Date \n",
"City \n",
"Los Angeles 4 "
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de banques en faillite n'ont pas le mot \"Bank\" dans leur nom?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 55,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"14"
]
},
"execution_count": 55,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de noms de banques commencent par la lettre 's' ?"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"53"
]
},
"execution_count": 58,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de valeurs CERT sont supérieures à 20000 ?"
]
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"417"
]
},
"execution_count": 64,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de noms de banques se composent de seulement deux mots ? (par exemple \"First Bank\" et \"Bank Georgia\")"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"114"
]
},
"execution_count": 67,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Bonus: Combien de banques ont fermé en 2008 ? (c'est difficile parce que techniquement nous n'avons pas encore vu les séries temporelles avec pandas ! N'hésitez pas à passer !"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 54,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"25"
]
},
"execution_count": 54,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!"
]
}
],
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -0,0 +1,787 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pandas Exercices - Solutions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Il est temps de tester vos nouvelles compétences en pandas ! Utilisez le fichier csv de ce dossier pour effectuer les tâches en gras ci-dessous!\n",
"\n",
"#### NOTE : TOUTES LES TÂCHES DOIVENT ÊTRE EFFECTUÉES SUR UNE SEULE LIGNE AVEC DU CODE PANDAS. BLOQUé(e) ? PAS DE PROBLÈME ! CONSULTEZ LE NOTEBOOK AVEC LES SOLUTIONS ! "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Importer pandas et lire le fichier banklist.csv dans un dataframe nommé banks. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"banks = pd.read_csv('banklist.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Afficher les 5 premières lignes du dataframe"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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>Bank Name</th>\n",
" <th>City</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Fayette County Bank</td>\n",
" <td>Saint Elmo</td>\n",
" <td>IL</td>\n",
" <td>1802</td>\n",
" <td>United Fidelity Bank, fsb</td>\n",
" <td>26-May-17</td>\n",
" <td>1-Jun-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Guaranty Bank, (d/b/a BestBank in Georgia &amp; Mi...</td>\n",
" <td>Milwaukee</td>\n",
" <td>WI</td>\n",
" <td>30003</td>\n",
" <td>First-Citizens Bank &amp; Trust Company</td>\n",
" <td>5-May-17</td>\n",
" <td>1-Jun-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>First NBC Bank</td>\n",
" <td>New Orleans</td>\n",
" <td>LA</td>\n",
" <td>58302</td>\n",
" <td>Whitney Bank</td>\n",
" <td>28-Apr-17</td>\n",
" <td>23-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Proficio Bank</td>\n",
" <td>Cottonwood Heights</td>\n",
" <td>UT</td>\n",
" <td>35495</td>\n",
" <td>Cache Valley Bank</td>\n",
" <td>3-Mar-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Seaway Bank and Trust Company</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>19328</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>27-Jan-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name City ST \\\n",
"0 Fayette County Bank Saint Elmo IL \n",
"1 Guaranty Bank, (d/b/a BestBank in Georgia & Mi... Milwaukee WI \n",
"2 First NBC Bank New Orleans LA \n",
"3 Proficio Bank Cottonwood Heights UT \n",
"4 Seaway Bank and Trust Company Chicago IL \n",
"\n",
" CERT Acquiring Institution Closing Date Updated Date \n",
"0 1802 United Fidelity Bank, fsb 26-May-17 1-Jun-17 \n",
"1 30003 First-Citizens Bank & Trust Company 5-May-17 1-Jun-17 \n",
"2 58302 Whitney Bank 28-Apr-17 23-May-17 \n",
"3 35495 Cache Valley Bank 3-Mar-17 18-May-17 \n",
"4 19328 State Bank of Texas 27-Jan-17 18-May-17 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les noms de colonne?"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Bank Name', 'City', 'ST', 'CERT', 'Acquiring Institution',\n",
" 'Closing Date', 'Updated Date'],\n",
" dtype='object')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks.columns"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien d'états (ST) sont représentés dans cet ensemble de données?"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"44"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks['ST'].nunique()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Obtenir une liste ou tableau de tous les états du dataset."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['IL', 'WI', 'LA', 'UT', 'NJ', 'AR', 'GA', 'PA', 'TN', 'WA', 'CO',\n",
" 'PR', 'FL', 'MN', 'CA', 'MD', 'OK', 'OH', 'SC', 'VA', 'ID', 'TX',\n",
" 'CT', 'AZ', 'NV', 'NC', 'KY', 'MO', 'KS', 'AL', 'MI', 'IN', 'IA',\n",
" 'NE', 'MS', 'NM', 'OR', 'NY', 'MA', 'SD', 'WY', 'WV', 'NH', 'HI'],\n",
" dtype=object)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks['ST'].unique()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les 5 états avec le plus de banques en faillite?"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"ST\n",
"GA 93\n",
"FL 75\n",
"IL 67\n",
"CA 41\n",
"MN 23\n",
"Name: Bank Name, dtype: int64"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks.groupby(\"ST\").count().sort_values('Bank Name',ascending=False).iloc[:5]['Bank Name']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les 5 principaux établissements acquéreurs?"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"No Acquirer 31\n",
"State Bank and Trust Company 12\n",
"First-Citizens Bank & Trust Company 11\n",
"Ameris Bank 10\n",
"U.S. Bank N.A. 9\n",
"Name: Acquiring Institution, dtype: int64"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks['Acquiring Institution'].value_counts().iloc[:5]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de banques State Bank of Texas a-t-elle acquises ? Combien d'entre elles étaient au Texas ?"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 16,
"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>Bank Name</th>\n",
" <th>City</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Seaway Bank and Trust Company</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>19328</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>27-Jan-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>The National Republic Bank of Chicago</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>916</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>24-Oct-14</td>\n",
" <td>6-Jan-16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>450</th>\n",
" <td>Millennium State Bank of Texas</td>\n",
" <td>Dallas</td>\n",
" <td>TX</td>\n",
" <td>57667</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>2-Jul-09</td>\n",
" <td>26-Oct-12</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name City ST CERT \\\n",
"4 Seaway Bank and Trust Company Chicago IL 19328 \n",
"21 The National Republic Bank of Chicago Chicago IL 916 \n",
"450 Millennium State Bank of Texas Dallas TX 57667 \n",
"\n",
" Acquiring Institution Closing Date Updated Date \n",
"4 State Bank of Texas 27-Jan-17 18-May-17 \n",
"21 State Bank of Texas 24-Oct-14 6-Jan-16 \n",
"450 State Bank of Texas 2-Jul-09 26-Oct-12 "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks[banks['Acquiring Institution']=='State Bank of Texas']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quelle est la ville la plus fréquente en Californie pour qu'une banque fasse faillite ?"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"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>Bank Name</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" <tr>\n",
" <th>City</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Los Angeles</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name ST CERT Acquiring Institution Closing Date \\\n",
"City \n",
"Los Angeles 4 4 4 4 4 \n",
"\n",
" Updated Date \n",
"City \n",
"Los Angeles 4 "
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks[banks['ST']=='CA'].groupby('City').count().sort_values('Bank Name',ascending=False).head(1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de banques en faillite n'ont pas le mot \"Bank\" dans leur nom?"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"14"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# banks['Bank Name'].apply(lambda name: 'Bank' not in name).value_counts()\n",
"sum(banks['Bank Name'].apply(lambda name: 'Bank' not in name))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de noms de banques commencent par la lettre 's' ?"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"53"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(banks['Bank Name'].apply(lambda name:name[0].upper() =='S'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de valeurs CERT sont supérieures à 20000 ?"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"417"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(banks['CERT']>20000)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de noms de banques se composent de seulement deux mots ? (par exemple \"First Bank\" et \"Bank Georgia\")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"114"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(banks['Bank Name'].apply(lambda name: len(name.split())==2))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Bonus: Combien de banques ont fermé en 2008 ? (c'est difficile parce que techniquement nous n'avons pas encore vu les séries temporelles avec pandas ! N'hésitez pas à passer !"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"25"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# ON APPRENDRA UN MEILLEUR MOYEN POUR FAIRE CELA BIENTOT!\n",
"sum(banks['Closing Date'].apply(lambda date: date[-2:]) == '08')\n",
"\n",
"# Meilleure solution\n",
"# sum(pd.to_datetime(banks['Closing Date']).apply(lambda date: date.year) == 2008)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!"
]
}
],
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -0,0 +1,787 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pandas Exercices - Solutions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Il est temps de tester vos nouvelles compétences en pandas ! Utilisez le fichier csv de ce dossier pour effectuer les tâches en gras ci-dessous!\n",
"\n",
"#### NOTE : TOUTES LES TÂCHES DOIVENT ÊTRE EFFECTUÉES SUR UNE SEULE LIGNE AVEC DU CODE PANDAS. BLOQUé(e) ? PAS DE PROBLÈME ! CONSULTEZ LE NOTEBOOK AVEC LES SOLUTIONS ! "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Importer pandas et lire le fichier banklist.csv dans un dataframe nommé banks. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"banks = pd.read_csv('banklist.csv')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Afficher les 5 premières lignes du dataframe"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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>Bank Name</th>\n",
" <th>City</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Fayette County Bank</td>\n",
" <td>Saint Elmo</td>\n",
" <td>IL</td>\n",
" <td>1802</td>\n",
" <td>United Fidelity Bank, fsb</td>\n",
" <td>26-May-17</td>\n",
" <td>1-Jun-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Guaranty Bank, (d/b/a BestBank in Georgia &amp; Mi...</td>\n",
" <td>Milwaukee</td>\n",
" <td>WI</td>\n",
" <td>30003</td>\n",
" <td>First-Citizens Bank &amp; Trust Company</td>\n",
" <td>5-May-17</td>\n",
" <td>1-Jun-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>First NBC Bank</td>\n",
" <td>New Orleans</td>\n",
" <td>LA</td>\n",
" <td>58302</td>\n",
" <td>Whitney Bank</td>\n",
" <td>28-Apr-17</td>\n",
" <td>23-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Proficio Bank</td>\n",
" <td>Cottonwood Heights</td>\n",
" <td>UT</td>\n",
" <td>35495</td>\n",
" <td>Cache Valley Bank</td>\n",
" <td>3-Mar-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Seaway Bank and Trust Company</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>19328</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>27-Jan-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name City ST \\\n",
"0 Fayette County Bank Saint Elmo IL \n",
"1 Guaranty Bank, (d/b/a BestBank in Georgia & Mi... Milwaukee WI \n",
"2 First NBC Bank New Orleans LA \n",
"3 Proficio Bank Cottonwood Heights UT \n",
"4 Seaway Bank and Trust Company Chicago IL \n",
"\n",
" CERT Acquiring Institution Closing Date Updated Date \n",
"0 1802 United Fidelity Bank, fsb 26-May-17 1-Jun-17 \n",
"1 30003 First-Citizens Bank & Trust Company 5-May-17 1-Jun-17 \n",
"2 58302 Whitney Bank 28-Apr-17 23-May-17 \n",
"3 35495 Cache Valley Bank 3-Mar-17 18-May-17 \n",
"4 19328 State Bank of Texas 27-Jan-17 18-May-17 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les noms de colonne?"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Bank Name', 'City', 'ST', 'CERT', 'Acquiring Institution',\n",
" 'Closing Date', 'Updated Date'],\n",
" dtype='object')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks.columns"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien d'états (ST) sont représentés dans cet ensemble de données?"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"44"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks['ST'].nunique()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Obtenir une liste ou tableau de tous les états du dataset."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['IL', 'WI', 'LA', 'UT', 'NJ', 'AR', 'GA', 'PA', 'TN', 'WA', 'CO',\n",
" 'PR', 'FL', 'MN', 'CA', 'MD', 'OK', 'OH', 'SC', 'VA', 'ID', 'TX',\n",
" 'CT', 'AZ', 'NV', 'NC', 'KY', 'MO', 'KS', 'AL', 'MI', 'IN', 'IA',\n",
" 'NE', 'MS', 'NM', 'OR', 'NY', 'MA', 'SD', 'WY', 'WV', 'NH', 'HI'],\n",
" dtype=object)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks['ST'].unique()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les 5 états avec le plus de banques en faillite?"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"ST\n",
"GA 93\n",
"FL 75\n",
"IL 67\n",
"CA 41\n",
"MN 23\n",
"Name: Bank Name, dtype: int64"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks.groupby(\"ST\").count().sort_values('Bank Name',ascending=False).iloc[:5]['Bank Name']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les 5 principaux établissements acquéreurs?"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"No Acquirer 31\n",
"State Bank and Trust Company 12\n",
"First-Citizens Bank & Trust Company 11\n",
"Ameris Bank 10\n",
"U.S. Bank N.A. 9\n",
"Name: Acquiring Institution, dtype: int64"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks['Acquiring Institution'].value_counts().iloc[:5]"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de banques State Bank of Texas a-t-elle acquises ? Combien d'entre elles étaient au Texas ?"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 16,
"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>Bank Name</th>\n",
" <th>City</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Seaway Bank and Trust Company</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>19328</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>27-Jan-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>The National Republic Bank of Chicago</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>916</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>24-Oct-14</td>\n",
" <td>6-Jan-16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>450</th>\n",
" <td>Millennium State Bank of Texas</td>\n",
" <td>Dallas</td>\n",
" <td>TX</td>\n",
" <td>57667</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>2-Jul-09</td>\n",
" <td>26-Oct-12</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name City ST CERT \\\n",
"4 Seaway Bank and Trust Company Chicago IL 19328 \n",
"21 The National Republic Bank of Chicago Chicago IL 916 \n",
"450 Millennium State Bank of Texas Dallas TX 57667 \n",
"\n",
" Acquiring Institution Closing Date Updated Date \n",
"4 State Bank of Texas 27-Jan-17 18-May-17 \n",
"21 State Bank of Texas 24-Oct-14 6-Jan-16 \n",
"450 State Bank of Texas 2-Jul-09 26-Oct-12 "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks[banks['Acquiring Institution']=='State Bank of Texas']"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quelle est la ville la plus fréquente en Californie pour qu'une banque fasse faillite ?"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"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>Bank Name</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" <tr>\n",
" <th>City</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Los Angeles</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name ST CERT Acquiring Institution Closing Date \\\n",
"City \n",
"Los Angeles 4 4 4 4 4 \n",
"\n",
" Updated Date \n",
"City \n",
"Los Angeles 4 "
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"banks[banks['ST']=='CA'].groupby('City').count().sort_values('Bank Name',ascending=False).head(1)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de banques en faillite n'ont pas le mot \"Bank\" dans leur nom?"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"14"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# banks['Bank Name'].apply(lambda name: 'Bank' not in name).value_counts()\n",
"sum(banks['Bank Name'].apply(lambda name: 'Bank' not in name))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de noms de banques commencent par la lettre 's' ?"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"53"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(banks['Bank Name'].apply(lambda name:name[0].upper() =='S'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de valeurs CERT sont supérieures à 20000 ?"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"417"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(banks['CERT']>20000)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de noms de banques se composent de seulement deux mots ? (par exemple \"First Bank\" et \"Bank Georgia\")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"114"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sum(banks['Bank Name'].apply(lambda name: len(name.split())==2))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Bonus: Combien de banques ont fermé en 2008 ? (c'est difficile parce que techniquement nous n'avons pas encore vu les séries temporelles avec pandas ! N'hésitez pas à passer !"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"25"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# ON APPRENDRA UN MEILLEUR MOYEN POUR FAIRE CELA BIENTOT!\n",
"sum(banks['Closing Date'].apply(lambda date: date[-2:]) == '08')\n",
"\n",
"# Meilleure solution\n",
"# sum(pd.to_datetime(banks['Closing Date']).apply(lambda date: date.year) == 2008)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!"
]
}
],
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -0,0 +1,907 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pandas Exercices - Solutions"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Il est temps de tester vos nouvelles compétences en pandas ! Utilisez le fichier csv de ce dossier pour effectuer les tâches en gras ci-dessous!\n",
"\n",
"#### NOTE : TOUTES LES TÂCHES DOIVENT ÊTRE EFFECTUÉES SUR UNE SEULE LIGNE AVEC DU CODE PANDAS. BLOQUé(e) ? PAS DE PROBLÈME ! CONSULTEZ LE NOTEBOOK AVEC LES SOLUTIONS ! "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Importer pandas et lire le fichier banklist.csv dans un dataframe nommé banks. "
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"df=pd.read_csv(\"banklist.csv\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Afficher les 5 premières lignes du dataframe"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Bank Name City ST \\\n",
"0 Fayette County Bank Saint Elmo IL \n",
"1 Guaranty Bank, (d/b/a BestBank in Georgia & Mi... Milwaukee WI \n",
"2 First NBC Bank New Orleans LA \n",
"3 Proficio Bank Cottonwood Heights UT \n",
"4 Seaway Bank and Trust Company Chicago IL \n",
"\n",
" CERT Acquiring Institution Closing Date Updated Date \n",
"0 1802 United Fidelity Bank, fsb 26-May-17 1-Jun-17 \n",
"1 30003 First-Citizens Bank & Trust Company 5-May-17 1-Jun-17 \n",
"2 58302 Whitney Bank 28-Apr-17 23-May-17 \n",
"3 35495 Cache Valley Bank 3-Mar-17 18-May-17 \n",
"4 19328 State Bank of Texas 27-Jan-17 18-May-17 "
],
"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>Bank Name</th>\n <th>City</th>\n <th>ST</th>\n <th>CERT</th>\n <th>Acquiring Institution</th>\n <th>Closing Date</th>\n <th>Updated Date</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>0</th>\n <td>Fayette County Bank</td>\n <td>Saint Elmo</td>\n <td>IL</td>\n <td>1802</td>\n <td>United Fidelity Bank, fsb</td>\n <td>26-May-17</td>\n <td>1-Jun-17</td>\n </tr>\n <tr>\n <th>1</th>\n <td>Guaranty Bank, (d/b/a BestBank in Georgia &amp; Mi...</td>\n <td>Milwaukee</td>\n <td>WI</td>\n <td>30003</td>\n <td>First-Citizens Bank &amp; Trust Company</td>\n <td>5-May-17</td>\n <td>1-Jun-17</td>\n </tr>\n <tr>\n <th>2</th>\n <td>First NBC Bank</td>\n <td>New Orleans</td>\n <td>LA</td>\n <td>58302</td>\n <td>Whitney Bank</td>\n <td>28-Apr-17</td>\n <td>23-May-17</td>\n </tr>\n <tr>\n <th>3</th>\n <td>Proficio Bank</td>\n <td>Cottonwood Heights</td>\n <td>UT</td>\n <td>35495</td>\n <td>Cache Valley Bank</td>\n <td>3-Mar-17</td>\n <td>18-May-17</td>\n </tr>\n <tr>\n <th>4</th>\n <td>Seaway Bank and Trust Company</td>\n <td>Chicago</td>\n <td>IL</td>\n <td>19328</td>\n <td>State Bank of Texas</td>\n <td>27-Jan-17</td>\n <td>18-May-17</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 11
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"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>Bank Name</th>\n",
" <th>City</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>Fayette County Bank</td>\n",
" <td>Saint Elmo</td>\n",
" <td>IL</td>\n",
" <td>1802</td>\n",
" <td>United Fidelity Bank, fsb</td>\n",
" <td>26-May-17</td>\n",
" <td>1-Jun-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>1</th>\n",
" <td>Guaranty Bank, (d/b/a BestBank in Georgia &amp; Mi...</td>\n",
" <td>Milwaukee</td>\n",
" <td>WI</td>\n",
" <td>30003</td>\n",
" <td>First-Citizens Bank &amp; Trust Company</td>\n",
" <td>5-May-17</td>\n",
" <td>1-Jun-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2</th>\n",
" <td>First NBC Bank</td>\n",
" <td>New Orleans</td>\n",
" <td>LA</td>\n",
" <td>58302</td>\n",
" <td>Whitney Bank</td>\n",
" <td>28-Apr-17</td>\n",
" <td>23-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>3</th>\n",
" <td>Proficio Bank</td>\n",
" <td>Cottonwood Heights</td>\n",
" <td>UT</td>\n",
" <td>35495</td>\n",
" <td>Cache Valley Bank</td>\n",
" <td>3-Mar-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Seaway Bank and Trust Company</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>19328</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>27-Jan-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name City ST \\\n",
"0 Fayette County Bank Saint Elmo IL \n",
"1 Guaranty Bank, (d/b/a BestBank in Georgia & Mi... Milwaukee WI \n",
"2 First NBC Bank New Orleans LA \n",
"3 Proficio Bank Cottonwood Heights UT \n",
"4 Seaway Bank and Trust Company Chicago IL \n",
"\n",
" CERT Acquiring Institution Closing Date Updated Date \n",
"0 1802 United Fidelity Bank, fsb 26-May-17 1-Jun-17 \n",
"1 30003 First-Citizens Bank & Trust Company 5-May-17 1-Jun-17 \n",
"2 58302 Whitney Bank 28-Apr-17 23-May-17 \n",
"3 35495 Cache Valley Bank 3-Mar-17 18-May-17 \n",
"4 19328 State Bank of Texas 27-Jan-17 18-May-17 "
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les noms de colonne?"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Index(['Bank Name', 'City', 'ST', 'CERT', 'Acquiring Institution',\n",
" 'Closing Date', 'Updated Date'],\n",
" dtype='object')"
]
},
"metadata": {},
"execution_count": 13
}
],
"source": [
"df.columns"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"Index(['Bank Name', 'City', 'ST', 'CERT', 'Acquiring Institution',\n",
" 'Closing Date', 'Updated Date'],\n",
" dtype='object')"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien d'états (ST) sont représentés dans cet ensemble de données?"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"44"
]
},
"metadata": {},
"execution_count": 18
}
],
"source": [
"df[\"ST\"].nunique()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"44"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Obtenir une liste ou tableau de tous les états du dataset."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"array(['IL', 'WI', 'LA', 'UT', 'NJ', 'AR', 'GA', 'PA', 'TN', 'WA', 'CO',\n",
" 'PR', 'FL', 'MN', 'CA', 'MD', 'OK', 'OH', 'SC', 'VA', 'ID', 'TX',\n",
" 'CT', 'AZ', 'NV', 'NC', 'KY', 'MO', 'KS', 'AL', 'MI', 'IN', 'IA',\n",
" 'NE', 'MS', 'NM', 'OR', 'NY', 'MA', 'SD', 'WY', 'WV', 'NH', 'HI'],\n",
" dtype=object)"
]
},
"metadata": {},
"execution_count": 19
}
],
"source": [
"df[\"ST\"].unique()"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array(['IL', 'WI', 'LA', 'UT', 'NJ', 'AR', 'GA', 'PA', 'TN', 'WA', 'CO',\n",
" 'PR', 'FL', 'MN', 'CA', 'MD', 'OK', 'OH', 'SC', 'VA', 'ID', 'TX',\n",
" 'CT', 'AZ', 'NV', 'NC', 'KY', 'MO', 'KS', 'AL', 'MI', 'IN', 'IA',\n",
" 'NE', 'MS', 'NM', 'OR', 'NY', 'MA', 'SD', 'WY', 'WV', 'NH', 'HI'],\n",
" dtype=object)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les 5 états avec le plus de banques en faillite?"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"scrolled": true
},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"ST\n",
"GA 93\n",
"FL 75\n",
"IL 67\n",
"CA 41\n",
"MN 23\n",
"dtype: int64"
]
},
"metadata": {},
"execution_count": 27
}
],
"source": [
"df.value_counts(\"ST\").sort_values(ascending=False).head()"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"ST\n",
"GA 93\n",
"FL 75\n",
"IL 67\n",
"CA 41\n",
"MN 23\n",
"Name: Bank Name, dtype: int64"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quels sont les 5 principaux établissements acquéreurs?"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"No Acquirer 31\n",
"State Bank and Trust Company 12\n",
"First-Citizens Bank & Trust Company 11\n",
"Ameris Bank 10\n",
"U.S. Bank N.A. 9\n",
"Name: Acquiring Institution, dtype: int64"
]
},
"metadata": {},
"execution_count": 29
}
],
"source": [
"df[\"Acquiring Institution\"].value_counts().sort_values(ascending=False).head()"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"No Acquirer 31\n",
"State Bank and Trust Company 12\n",
"First-Citizens Bank & Trust Company 11\n",
"Ameris Bank 10\n",
"U.S. Bank N.A. 9\n",
"Name: Acquiring Institution, dtype: int64"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de banques State Bank of Texas a-t-elle acquises ? Combien d'entre elles étaient au Texas ?"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Bank Name City ST CERT \\\n",
"4 Seaway Bank and Trust Company Chicago IL 19328 \n",
"21 The National Republic Bank of Chicago Chicago IL 916 \n",
"450 Millennium State Bank of Texas Dallas TX 57667 \n",
"\n",
" Acquiring Institution Closing Date Updated Date \n",
"4 State Bank of Texas 27-Jan-17 18-May-17 \n",
"21 State Bank of Texas 24-Oct-14 6-Jan-16 \n",
"450 State Bank of Texas 2-Jul-09 26-Oct-12 "
],
"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>Bank Name</th>\n <th>City</th>\n <th>ST</th>\n <th>CERT</th>\n <th>Acquiring Institution</th>\n <th>Closing Date</th>\n <th>Updated Date</th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>4</th>\n <td>Seaway Bank and Trust Company</td>\n <td>Chicago</td>\n <td>IL</td>\n <td>19328</td>\n <td>State Bank of Texas</td>\n <td>27-Jan-17</td>\n <td>18-May-17</td>\n </tr>\n <tr>\n <th>21</th>\n <td>The National Republic Bank of Chicago</td>\n <td>Chicago</td>\n <td>IL</td>\n <td>916</td>\n <td>State Bank of Texas</td>\n <td>24-Oct-14</td>\n <td>6-Jan-16</td>\n </tr>\n <tr>\n <th>450</th>\n <td>Millennium State Bank of Texas</td>\n <td>Dallas</td>\n <td>TX</td>\n <td>57667</td>\n <td>State Bank of Texas</td>\n <td>2-Jul-09</td>\n <td>26-Oct-12</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 30
}
],
"source": [
"df[(df[\"Acquiring Institution\"]==\"State Bank of Texas\")]"
]
},
{
"cell_type": "code",
"execution_count": 16,
"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>Bank Name</th>\n",
" <th>City</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>4</th>\n",
" <td>Seaway Bank and Trust Company</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>19328</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>27-Jan-17</td>\n",
" <td>18-May-17</td>\n",
" </tr>\n",
" <tr>\n",
" <th>21</th>\n",
" <td>The National Republic Bank of Chicago</td>\n",
" <td>Chicago</td>\n",
" <td>IL</td>\n",
" <td>916</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>24-Oct-14</td>\n",
" <td>6-Jan-16</td>\n",
" </tr>\n",
" <tr>\n",
" <th>450</th>\n",
" <td>Millennium State Bank of Texas</td>\n",
" <td>Dallas</td>\n",
" <td>TX</td>\n",
" <td>57667</td>\n",
" <td>State Bank of Texas</td>\n",
" <td>2-Jul-09</td>\n",
" <td>26-Oct-12</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name City ST CERT \\\n",
"4 Seaway Bank and Trust Company Chicago IL 19328 \n",
"21 The National Republic Bank of Chicago Chicago IL 916 \n",
"450 Millennium State Bank of Texas Dallas TX 57667 \n",
"\n",
" Acquiring Institution Closing Date Updated Date \n",
"4 State Bank of Texas 27-Jan-17 18-May-17 \n",
"21 State Bank of Texas 24-Oct-14 6-Jan-16 \n",
"450 State Bank of Texas 2-Jul-09 26-Oct-12 "
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Quelle est la ville la plus fréquente en Californie pour qu'une banque fasse faillite ?"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Bank Name ST CERT Acquiring Institution Closing Date \\\n",
"City \n",
"Los Angeles 4 4 4 4 4 \n",
"\n",
" Updated Date \n",
"City \n",
"Los Angeles 4 "
],
"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>Bank Name</th>\n <th>ST</th>\n <th>CERT</th>\n <th>Acquiring Institution</th>\n <th>Closing Date</th>\n <th>Updated Date</th>\n </tr>\n <tr>\n <th>City</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>Los Angeles</th>\n <td>4</td>\n <td>4</td>\n <td>4</td>\n <td>4</td>\n <td>4</td>\n <td>4</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 36
}
],
"source": [
"df[df['ST']=='CA'].groupby('City').count().sort_values('Bank Name',ascending=False).head(1)"
]
},
{
"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>Bank Name</th>\n",
" <th>ST</th>\n",
" <th>CERT</th>\n",
" <th>Acquiring Institution</th>\n",
" <th>Closing Date</th>\n",
" <th>Updated Date</th>\n",
" </tr>\n",
" <tr>\n",
" <th>City</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>Los Angeles</th>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" <td>4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Bank Name ST CERT Acquiring Institution Closing Date \\\n",
"City \n",
"Los Angeles 4 4 4 4 4 \n",
"\n",
" Updated Date \n",
"City \n",
"Los Angeles 4 "
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de banques en faillite n'ont pas le mot \"Bank\" dans leur nom?"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"False 537\n",
"True 14\n",
"Name: Bank Name, dtype: int64"
]
},
"metadata": {},
"execution_count": 43
}
],
"source": [
"df['Bank Name'].apply(lambda name: 'Bank' not in name).value_counts()"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"14"
]
},
"execution_count": 20,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de noms de banques commencent par la lettre 's' ?"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"53"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de valeurs CERT sont supérieures à 20000 ?"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"417"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"##### Combien de noms de banques se composent de seulement deux mots ? (par exemple \"First Bank\" et \"Bank Georgia\")"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"114"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Bonus: Combien de banques ont fermé en 2008 ? (c'est difficile parce que techniquement nous n'avons pas encore vu les séries temporelles avec pandas ! N'hésitez pas à passer !"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {},
"outputs": [],
"source": [
"# CODE ICI"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"25"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Bon travail!"
]
}
],
"metadata": {
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.9 64-bit ('pyfinance': conda)",
"metadata": {
"interpreter": {
"hash": "e89404a230d8800c54ad520c7b67d1bd9bb833a07b37dd3e521a178a3dc34904"
}
}
},
"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.7.9-final"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

View File

@ -0,0 +1,552 @@
Bank Name,City,ST,CERT,Acquiring Institution,Closing Date,Updated Date
Fayette County Bank,Saint Elmo,IL,1802,"United Fidelity Bank, fsb",26-May-17,1-Jun-17
"Guaranty Bank, (d/b/a BestBank in Georgia & Michigan) ",Milwaukee,WI,30003,First-Citizens Bank & Trust Company,5-May-17,1-Jun-17
First NBC Bank,New Orleans,LA,58302,Whitney Bank,28-Apr-17,23-May-17
Proficio Bank,Cottonwood Heights,UT,35495,Cache Valley Bank,3-Mar-17,18-May-17
Seaway Bank and Trust Company,Chicago,IL,19328,State Bank of Texas,27-Jan-17,18-May-17
Harvest Community Bank,Pennsville,NJ,34951,First-Citizens Bank & Trust Company,13-Jan-17,18-May-17
Allied Bank,Mulberry,AR,91,Today's Bank,23-Sep-16,17-Nov-16
The Woodbury Banking Company,Woodbury,GA,11297,United Bank,19-Aug-16,1-Jun-17
First CornerStone Bank,King of Prussia,PA,35312,First-Citizens Bank & Trust Company,6-May-16,6-Sep-16
Trust Company Bank,Memphis,TN,9956,The Bank of Fayette County,29-Apr-16,6-Sep-16
North Milwaukee State Bank,Milwaukee,WI,20364,First-Citizens Bank & Trust Company,11-Mar-16,13-Mar-17
Hometown National Bank,Longview,WA,35156,Twin City Bank,2-Oct-15,13-Apr-16
The Bank of Georgia,Peachtree City,GA,35259,Fidelity Bank,2-Oct-15,24-Oct-16
Premier Bank,Denver,CO,34112,"United Fidelity Bank, fsb",10-Jul-15,17-Aug-16
Edgebrook Bank,Chicago,IL,57772,Republic Bank of Chicago,8-May-15,12-Jul-16
Doral Bank,San Juan,PR,32102,Banco Popular de Puerto Rico,27-Feb-15,13-May-15
Capitol City Bank & Trust Company,Atlanta,GA,33938,First-Citizens Bank & Trust Company,13-Feb-15,21-Apr-15
Highland Community Bank,Chicago,IL,20290,"United Fidelity Bank, fsb",23-Jan-15,21-Apr-15
First National Bank of Crestview ,Crestview,FL,17557,First NBC Bank,16-Jan-15,8-May-17
Northern Star Bank,Mankato,MN,34983,BankVista,19-Dec-14,6-Jan-16
"Frontier Bank, FSB D/B/A El Paseo Bank",Palm Desert,CA,34738,"Bank of Southern California, N.A.",7-Nov-14,10-Nov-16
The National Republic Bank of Chicago,Chicago,IL,916,State Bank of Texas,24-Oct-14,6-Jan-16
NBRS Financial,Rising Sun,MD,4862,Howard Bank,17-Oct-14,26-Mar-15
"GreenChoice Bank, fsb",Chicago,IL,28462,"Providence Bank, LLC",25-Jul-14,12-Dec-16
Eastside Commercial Bank,Conyers,GA,58125,Community & Southern Bank,18-Jul-14,11-Jul-16
The Freedom State Bank ,Freedom,OK,12483,Alva State Bank & Trust Company,27-Jun-14,25-Mar-16
Valley Bank,Fort Lauderdale,FL,21793,"Landmark Bank, National Association",20-Jun-14,29-Jun-15
Valley Bank,Moline,IL,10450,Great Southern Bank,20-Jun-14,26-Jun-15
Slavie Federal Savings Bank,Bel Air,MD,32368,"Bay Bank, FSB",30-May-14,12-Dec-16
Columbia Savings Bank,Cincinnati,OH,32284,"United Fidelity Bank, fsb",23-May-14,10-Nov-16
AztecAmerica Bank ,Berwyn,IL,57866,Republic Bank of Chicago,16-May-14,20-Oct-16
Allendale County Bank,Fairfax,SC,15062,Palmetto State Bank,25-Apr-14,18-Jul-14
Vantage Point Bank,Horsham,PA,58531,First Choice Bank,28-Feb-14,3-Mar-15
"Millennium Bank, National Association ",Sterling,VA,35096,WashingtonFirst Bank,28-Feb-14,3-Mar-15
Syringa Bank,Boise,ID,34296,Sunwest Bank,31-Jan-14,12-Apr-16
The Bank of Union,El Reno,OK,17967,BancFirst,24-Jan-14,25-Mar-16
DuPage National Bank,West Chicago,IL,5732,Republic Bank of Chicago,17-Jan-14,20-Oct-16
"Texas Community Bank, National Association",The Woodlands,TX,57431,"Spirit of Texas Bank, SSB",13-Dec-13,29-Dec-14
Bank of Jackson County,Graceville,FL,14794,First Federal Bank of Florida,30-Oct-13,20-Oct-16
First National Bank also operating as The National Bank of El Paso,Edinburg,TX,14318,PlainsCapital Bank,13-Sep-13,27-May-15
The Community's Bank,Bridgeport,CT,57041,No Acquirer,13-Sep-13,7-Dec-15
Sunrise Bank of Arizona,Phoenix,AZ,34707,"First Fidelity Bank, National Association",23-Aug-13,3-May-17
Community South Bank,Parsons,TN,19849,"CB&S Bank, Inc.",23-Aug-13,12-Sep-14
Bank of Wausau,Wausau,WI,35016,Nicolet National Bank,9-Aug-13,24-Oct-13
First Community Bank of Southwest Florida (also operating as Community Bank of Cape Coral),Fort Myers,FL,34943,C1 Bank,2-Aug-13,9-Feb-17
Mountain National Bank,Sevierville,TN,34789,"First Tennessee Bank, National Association",7-Jun-13,4-Feb-16
1st Commerce Bank,North Las Vegas,NV,58358,Plaza Bank,6-Jun-13,12-Jul-13
Banks of Wisconsin d/b/a Bank of Kenosha,Kenosha,WI,35386,"North Shore Bank, FSB",31-May-13,5-May-17
Central Arizona Bank,Scottsdale,AZ,34527,Western State Bank,14-May-13,7-Dec-15
Sunrise Bank,Valdosta,GA,58185,Synovus Bank,10-May-13,26-Jun-14
Pisgah Community Bank,Asheville,NC,58701,"Capital Bank, N.A.",10-May-13,8-Aug-16
Douglas County Bank,Douglasville,GA,21649,Hamilton State Bank,26-Apr-13,25-Apr-14
Parkway Bank,Lenoir,NC,57158,"CertusBank, National Association",26-Apr-13,20-Oct-16
Chipola Community Bank,Marianna,FL,58034,First Federal Bank of Florida,19-Apr-13,21-Sep-15
Heritage Bank of North Florida,Orange Park,FL,26680,FirstAtlantic Bank,19-Apr-13,8-Aug-16
First Federal Bank,Lexington,KY,29594,Your Community Bank,19-Apr-13,12-Dec-16
Gold Canyon Bank,Gold Canyon,AZ,58066,"First Scottsdale Bank, National Association",5-Apr-13,7-Oct-15
Frontier Bank,LaGrange,GA,16431,HeritageBank of the South,8-Mar-13,2-Mar-16
Covenant Bank,Chicago,IL,22476,Liberty Bank and Trust Company,15-Feb-13,21-Sep-15
1st Regents Bank,Andover,MN,57157,First Minnesota Bank,18-Jan-13,12-Jul-16
Westside Community Bank,University Place,WA,33997,Sunwest Bank,11-Jan-13,8-Aug-16
Community Bank of the Ozarks,Sunrise Beach,MO,27331,Bank of Sullivan,14-Dec-12,4-Apr-14
Hometown Community Bank,Braselton,GA,57928,"CertusBank, National Association",16-Nov-12,6-Jan-16
Citizens First National Bank,Princeton,IL,3731,Heartland Bank and Trust Company,2-Nov-12,22-Nov-13
Heritage Bank of Florida,Lutz,FL,35009,Centennial Bank,2-Nov-12,21-Mar-14
NOVA Bank,Berwyn,PA,27148,No Acquirer,26-Oct-12,24-Jan-13
Excel Bank,Sedalia,MO,19189,Simmons First National Bank,19-Oct-12,22-Oct-13
First East Side Savings Bank,Tamarac,FL,28144,Stearns Bank N.A.,19-Oct-12,6-Jan-16
GulfSouth Private Bank,Destin,FL,58073,SmartBank,19-Oct-12,21-Mar-14
First United Bank,Crete,IL,20685,"Old Plank Trail Community Bank, National Association",28-Sep-12,1-Nov-13
Truman Bank,St. Louis,MO,27316,Simmons First National Bank,14-Sep-12,17-Dec-12
First Commercial Bank,Bloomington,MN,35246,Republic Bank & Trust Company,7-Sep-12,17-Dec-12
Waukegan Savings Bank,Waukegan,IL,28243,First Midwest Bank,3-Aug-12,7-Dec-15
Jasper Banking Company,Jasper,GA,16240,Stearns Bank N.A.,27-Jul-12,21-Mar-14
Second Federal Savings and Loan Association of Chicago,Chicago,IL,27986,Hinsdale Bank & Trust Company,20-Jul-12,14-Jan-13
Heartland Bank,Leawood,KS,1361,Metcalf Bank,20-Jul-12,30-Jul-13
First Cherokee State Bank,Woodstock,GA,32711,Community & Southern Bank,20-Jul-12,6-Jun-16
Georgia Trust Bank,Buford,GA,57847,Community & Southern Bank,20-Jul-12,21-Mar-14
The Royal Palm Bank of Florida,Naples,FL,57096,First National Bank of the Gulf Coast,20-Jul-12,21-Mar-14
Glasgow Savings Bank,Glasgow,MO,1056,Regional Missouri Bank,13-Jul-12,19-Aug-14
Montgomery Bank & Trust,Ailey,GA,19498,Ameris Bank,6-Jul-12,21-Mar-14
The Farmers Bank of Lynchburg,Lynchburg,TN,1690,Clayton Bank and Trust,15-Jun-12,8-Aug-16
Security Exchange Bank,Marietta,GA,35299,Fidelity Bank,15-Jun-12,21-Mar-14
Putnam State Bank,Palatka,FL,27405,Harbor Community Bank,15-Jun-12,21-Mar-14
Waccamaw Bank,Whiteville,NC,34515,First Community Bank,8-Jun-12,21-Mar-14
Farmers' and Traders' State Bank,Shabbona,IL,9257,First State Bank,8-Jun-12,10-Oct-12
Carolina Federal Savings Bank,Charleston,SC,35372,Bank of North Carolina,8-Jun-12,21-Mar-14
First Capital Bank,Kingfisher,OK,416,F & M Bank,8-Jun-12,5-Feb-15
"Alabama Trust Bank, National Association",Sylacauga,AL,35224,Southern States Bank,18-May-12,21-Sep-15
"Security Bank, National Association",North Lauderdale,FL,23156,Banesco USA,4-May-12,12-Apr-16
Palm Desert National Bank,Palm Desert,CA,23632,Pacific Premier Bank,27-Apr-12,7-Dec-15
Plantation Federal Bank,Pawleys Island,SC,32503,First Federal Bank,27-Apr-12,10-Nov-16
"Inter Savings Bank, fsb D/B/A InterBank, fsb",Maple Grove,MN,31495,Great Southern Bank,27-Apr-12,17-May-13
HarVest Bank of Maryland,Gaithersburg,MD,57766,Sonabank,27-Apr-12,21-Sep-15
Bank of the Eastern Shore,Cambridge,MD,26759,No Acquirer,27-Apr-12,17-Oct-12
"Fort Lee Federal Savings Bank, FSB",Fort Lee,NJ,35527,Alma Bank,20-Apr-12,17-May-13
Fidelity Bank,Dearborn,MI,33883,The Huntington National Bank,30-Mar-12,4-Feb-14
Premier Bank,Wilmette,IL,35419,International Bank of Chicago,23-Mar-12,17-Oct-12
Covenant Bank & Trust,Rock Spring,GA,58068,"Stearns Bank, N.A.",23-Mar-12,21-Mar-14
New City Bank,Chicago,IL,57597,No Acquirer,9-Mar-12,29-Oct-12
Global Commerce Bank,Doraville,GA,34046,Metro City Bank,2-Mar-12,26-Jun-14
Home Savings of America,Little Falls,MN,29178,No Acquirer,24-Feb-12,17-Dec-12
Central Bank of Georgia,Ellaville,GA,5687,Ameris Bank,24-Feb-12,21-Mar-14
SCB Bank,Shelbyville,IN,29761,"First Merchants Bank, National Association",10-Feb-12,19-Feb-15
Charter National Bank and Trust,Hoffman Estates,IL,23187,"Barrington Bank & Trust Company, National Association",10-Feb-12,25-Mar-13
BankEast,Knoxville,TN,19869,"U.S. Bank, N.A.",27-Jan-12,7-Dec-15
Patriot Bank Minnesota,Forest Lake,MN,34823,First Resource Bank,27-Jan-12,12-Sep-12
Tennessee Commerce Bank,Franklin,TN,35296,Republic Bank & Trust Company,27-Jan-12,21-Mar-14
First Guaranty Bank and Trust Company of Jacksonville,Jacksonville,FL,16579,"CenterState Bank of Florida, N.A.",27-Jan-12,11-Jul-16
American Eagle Savings Bank,Boothwyn,PA,31581,"Capital Bank, N.A.",20-Jan-12,25-Jan-13
The First State Bank,Stockbridge,GA,19252,Hamilton State Bank,20-Jan-12,21-Mar-14
Central Florida State Bank,Belleview,FL,57186,"CenterState Bank of Florida, N.A.",20-Jan-12,6-Jun-16
Western National Bank,Phoenix,AZ,57917,Washington Federal,16-Dec-11,5-Feb-15
Premier Community Bank of the Emerald Coast,Crestview,FL,58343,Summit Bank,16-Dec-11,21-Mar-14
Central Progressive Bank,Lacombe,LA,19657,First NBC Bank,18-Nov-11,5-Feb-15
Polk County Bank,Johnston,IA,14194,Grinnell State Bank,18-Nov-11,15-Aug-12
Community Bank of Rockmart,Rockmart,GA,57860,Century Bank of Georgia,10-Nov-11,21-Mar-14
SunFirst Bank,Saint George,UT,57087,Cache Valley Bank,4-Nov-11,16-Nov-12
"Mid City Bank, Inc.",Omaha,NE,19397,Premier Bank,4-Nov-11,15-Aug-12
All American Bank,Des Plaines,IL,57759,International Bank of Chicago,28-Oct-11,15-Aug-12
Community Banks of Colorado,Greenwood Village,CO,21132,"Bank Midwest, N.A.",21-Oct-11,2-Jan-13
Community Capital Bank,Jonesboro,GA,57036,State Bank and Trust Company,21-Oct-11,6-Jan-16
Decatur First Bank,Decatur,GA,34392,Fidelity Bank,21-Oct-11,21-Mar-14
Old Harbor Bank,Clearwater,FL,57537,1st United Bank,21-Oct-11,21-Mar-14
Country Bank,Aledo,IL,35395,Blackhawk Bank & Trust,14-Oct-11,13-Apr-17
First State Bank,Cranford,NJ,58046,Northfield Bank,14-Oct-11,8-Nov-12
"Blue Ridge Savings Bank, Inc.",Asheville,NC,32347,Bank of North Carolina,14-Oct-11,21-Mar-14
Piedmont Community Bank,Gray,GA,57256,State Bank and Trust Company,14-Oct-11,21-Mar-14
Sun Security Bank,Ellington,MO,20115,Great Southern Bank,7-Oct-11,8-May-17
The RiverBank,Wyoming,MN,10216,Central Bank,7-Oct-11,7-Nov-12
First International Bank,Plano,TX,33513,American First National Bank,30-Sep-11,5-Feb-15
Citizens Bank of Northern California,Nevada City,CA,33983,Tri Counties Bank,23-Sep-11,9-Oct-12
Bank of the Commonwealth,Norfolk,VA,20408,Southern Bank and Trust Company,23-Sep-11,9-Oct-12
The First National Bank of Florida,Milton,FL,25155,CharterBank,9-Sep-11,21-Mar-14
CreekSide Bank,Woodstock,GA,58226,Georgia Commerce Bank,2-Sep-11,21-Mar-14
Patriot Bank of Georgia,Cumming,GA,58273,Georgia Commerce Bank,2-Sep-11,21-Mar-14
First Choice Bank,Geneva,IL,57212,Inland Bank & Trust,19-Aug-11,5-Feb-15
First Southern National Bank,Statesboro,GA,57239,Heritage Bank of the South,19-Aug-11,2-Mar-16
Lydian Private Bank,Palm Beach,FL,35356,"Sabadell United Bank, N.A.",19-Aug-11,21-Mar-14
Public Savings Bank,Huntingdon Valley,PA,34130,"Capital Bank, N.A.",18-Aug-11,15-Aug-12
The First National Bank of Olathe,Olathe,KS,4744,Enterprise Bank & Trust,12-Aug-11,23-Aug-12
Bank of Whitman,Colfax,WA,22528,Columbia State Bank,5-Aug-11,16-Aug-12
Bank of Shorewood,Shorewood,IL,22637,Heartland Bank and Trust Company,5-Aug-11,20-Oct-16
Integra Bank National Association,Evansville,IN,4392,Old National Bank,29-Jul-11,16-Aug-12
"BankMeridian, N.A.",Columbia,SC,58222,SCBT National Association,29-Jul-11,21-Mar-14
Virginia Business Bank,Richmond,VA,58283,Xenith Bank,29-Jul-11,9-Oct-12
Bank of Choice,Greeley,CO,2994,"Bank Midwest, N.A.",22-Jul-11,12-Sep-12
LandMark Bank of Florida,Sarasota,FL,35244,American Momentum Bank,22-Jul-11,21-Mar-14
Southshore Community Bank,Apollo Beach,FL,58056,American Momentum Bank,22-Jul-11,5-Feb-15
Summit Bank,Prescott,AZ,57442,The Foothills Bank,15-Jul-11,19-Aug-14
First Peoples Bank,Port St. Lucie,FL,34870,"Premier American Bank, N.A.",15-Jul-11,12-Jul-16
High Trust Bank,Stockbridge,GA,19554,Ameris Bank,15-Jul-11,21-Mar-14
One Georgia Bank,Atlanta,GA,58238,Ameris Bank,15-Jul-11,21-Mar-14
Signature Bank,Windsor,CO,57835,Points West Community Bank,8-Jul-11,26-Oct-12
Colorado Capital Bank,Castle Rock,CO,34522,First-Citizens Bank & Trust Company,8-Jul-11,10-Nov-16
First Chicago Bank & Trust,Chicago,IL,27935,Northbrook Bank & Trust Company,8-Jul-11,9-Sep-12
Mountain Heritage Bank,Clayton,GA,57593,First American Bank and Trust Company,24-Jun-11,9-Feb-17
First Commercial Bank of Tampa Bay,Tampa,FL,27583,Stonegate Bank,17-Jun-11,12-Sep-16
McIntosh State Bank,Jackson,GA,19237,Hamilton State Bank,17-Jun-11,21-Mar-14
Atlantic Bank and Trust,Charleston,SC,58420,"First Citizens Bank and Trust Company, Inc.",3-Jun-11,21-Mar-14
First Heritage Bank,Snohomish,WA,23626,Columbia State Bank,27-May-11,28-Jan-13
Summit Bank,Burlington,WA,513,Columbia State Bank,20-May-11,22-Jan-13
First Georgia Banking Company,Franklin,GA,57647,"CertusBank, National Association",20-May-11,21-Mar-14
Atlantic Southern Bank,Macon,GA,57213,"CertusBank, National Association",20-May-11,21-Mar-14
Coastal Bank,Cocoa Beach,FL,34898,"Florida Community Bank, a division of Premier American Bank, N.A.",6-May-11,21-Sep-15
Community Central Bank,Mount Clemens,MI,34234,Talmer Bank & Trust,29-Apr-11,13-Apr-17
The Park Avenue Bank,Valdosta,GA,19797,Bank of the Ozarks,29-Apr-11,21-Mar-14
First Choice Community Bank,Dallas,GA,58539,Bank of the Ozarks,29-Apr-11,21-Sep-15
Cortez Community Bank,Brooksville,FL,57625,"Florida Community Bank, a division of Premier American Bank, N.A.",29-Apr-11,8-Aug-16
First National Bank of Central Florida,Winter Park,FL,26297,"Florida Community Bank, a division of Premier American Bank, N.A.",29-Apr-11,4-May-16
Heritage Banking Group,Carthage,MS,14273,Trustmark National Bank,15-Apr-11,21-Mar-14
Rosemount National Bank,Rosemount,MN,24099,Central Bank,15-Apr-11,7-Dec-15
Superior Bank,Birmingham,AL,17750,"Superior Bank, National Association",15-Apr-11,21-Mar-14
Nexity Bank,Birmingham,AL,19794,AloStar Bank of Commerce,15-Apr-11,21-Mar-14
New Horizons Bank,East Ellijay,GA,57705,Citizens South Bank,15-Apr-11,21-Mar-14
Bartow County Bank,Cartersville,GA,21495,Hamilton State Bank,15-Apr-11,21-Mar-14
Nevada Commerce Bank,Las Vegas,NV,35418,City National Bank,8-Apr-11,9-Sep-12
Western Springs National Bank and Trust,Western Springs,IL,10086,Heartland Bank and Trust Company,8-Apr-11,22-Jan-13
The Bank of Commerce,Wood Dale,IL,34292,Advantage National Bank Group,25-Mar-11,22-Jan-13
Legacy Bank,Milwaukee,WI,34818,Seaway Bank and Trust Company,11-Mar-11,12-Sep-12
First National Bank of Davis,Davis,OK,4077,The Pauls Valley National Bank,11-Mar-11,13-Apr-17
Valley Community Bank,St. Charles,IL,34187,First State Bank,25-Feb-11,5-Feb-15
"San Luis Trust Bank, FSB",San Luis Obispo,CA,34783,First California Bank,18-Feb-11,12-Sep-16
Charter Oak Bank,Napa,CA,57855,Bank of Marin,18-Feb-11,12-Sep-12
Citizens Bank of Effingham,Springfield,GA,34601,Heritage Bank of the South,18-Feb-11,21-Mar-14
Habersham Bank,Clarkesville,GA,151,SCBT National Association,18-Feb-11,21-Mar-14
Canyon National Bank,Palm Springs,CA,34692,Pacific Premier Bank,11-Feb-11,19-Aug-14
Badger State Bank,Cassville,WI,13272,Royal Bank,11-Feb-11,12-Sep-12
Peoples State Bank,Hamtramck,MI,14939,First Michigan Bank,11-Feb-11,22-Jan-13
Sunshine State Community Bank,Port Orange,FL,35478,"Premier American Bank, N.A.",11-Feb-11,8-Aug-16
Community First Bank Chicago,Chicago,IL,57948,Northbrook Bank & Trust Company,4-Feb-11,20-Aug-12
North Georgia Bank,Watkinsville,GA,35242,BankSouth,4-Feb-11,21-Mar-14
American Trust Bank,Roswell,GA,57432,Renasant Bank,4-Feb-11,21-Mar-14
First Community Bank,Taos,NM,12261,"U.S. Bank, N.A.",28-Jan-11,12-Sep-12
FirsTier Bank,Louisville,CO,57646,No Acquirer,28-Jan-11,12-Sep-12
Evergreen State Bank,Stoughton,WI,5328,McFarland State Bank,28-Jan-11,12-Sep-12
The First State Bank,Camargo,OK,2303,Bank 7,28-Jan-11,12-Sep-12
United Western Bank,Denver,CO,31293,First-Citizens Bank & Trust Company,21-Jan-11,12-Sep-12
The Bank of Asheville,Asheville,NC,34516,First Bank,21-Jan-11,21-Mar-14
CommunitySouth Bank & Trust,Easley,SC,57868,"CertusBank, National Association",21-Jan-11,6-Jun-16
Enterprise Banking Company,McDonough,GA,19758,No Acquirer,21-Jan-11,21-Mar-14
Oglethorpe Bank,Brunswick,GA,57440,Bank of the Ozarks,14-Jan-11,21-Mar-14
Legacy Bank,Scottsdale,AZ,57820,Enterprise Bank & Trust,7-Jan-11,12-Apr-16
First Commercial Bank of Florida,Orlando,FL,34965,First Southern Bank,7-Jan-11,6-Jun-16
Community National Bank,Lino Lakes,MN,23306,Farmers & Merchants Savings Bank,17-Dec-10,10-Nov-16
First Southern Bank,Batesville,AR,58052,Southern Bank,17-Dec-10,20-Aug-12
"United Americas Bank, N.A.",Atlanta,GA,35065,State Bank and Trust Company,17-Dec-10,17-Oct-15
"Appalachian Community Bank, FSB",McCaysville,GA,58495,Peoples Bank of East Tennessee,17-Dec-10,21-Mar-14
Chestatee State Bank,Dawsonville,GA,34578,Bank of the Ozarks,17-Dec-10,21-Sep-15
"The Bank of Miami,N.A.",Coral Gables,FL,19040,1st United Bank,17-Dec-10,21-Mar-14
Earthstar Bank,Southampton,PA,35561,Polonia Bank,10-Dec-10,20-Aug-12
Paramount Bank,Farmington Hills,MI,34673,Level One Bank,10-Dec-10,21-Sep-15
First Banking Center,Burlington,WI,5287,First Michigan Bank,19-Nov-10,20-Aug-12
Allegiance Bank of North America,Bala Cynwyd,PA,35078,VIST Bank,19-Nov-10,20-Aug-12
Gulf State Community Bank,Carrabelle,FL,20340,Centennial Bank,19-Nov-10,12-Dec-16
Copper Star Bank,Scottsdale,AZ,35463,"Stearns Bank, N.A.",12-Nov-10,20-Aug-12
Darby Bank & Trust Co.,Vidalia,GA,14580,Ameris Bank,12-Nov-10,21-Mar-14
Tifton Banking Company,Tifton,GA,57831,Ameris Bank,12-Nov-10,21-Mar-14
First Vietnamese American Bank,Westminster,CA,57885,Grandpoint Bank,5-Nov-10,12-Sep-12
Pierce Commercial Bank,Tacoma,WA,34411,Heritage Bank,5-Nov-10,19-Oct-15
Western Commercial Bank,Woodland Hills,CA,58087,First California Bank,5-Nov-10,12-Sep-16
K Bank,Randallstown,MD,31263,Manufacturers and Traders Trust Company (M&T Bank),5-Nov-10,20-Aug-12
"First Arizona Savings, A FSB",Scottsdale,AZ,32582,No Acquirer,22-Oct-10,20-Aug-12
Hillcrest Bank,Overland Park,KS,22173,"Hillcrest Bank, N.A.",22-Oct-10,20-Aug-12
First Suburban National Bank,Maywood,IL,16089,Seaway Bank and Trust Company,22-Oct-10,20-Aug-12
The First National Bank of Barnesville,Barnesville,GA,2119,United Bank,22-Oct-10,17-Oct-15
The Gordon Bank,Gordon,GA,33904,Morris Bank,22-Oct-10,21-Mar-14
Progress Bank of Florida,Tampa,FL,32251,Bay Cities Bank,22-Oct-10,4-Feb-16
First Bank of Jacksonville,Jacksonville,FL,27573,Ameris Bank,22-Oct-10,21-Mar-14
Premier Bank,Jefferson City,MO,34016,Providence Bank,15-Oct-10,20-Aug-12
WestBridge Bank and Trust Company,Chesterfield,MO,58205,Midland States Bank,15-Oct-10,9-Feb-17
"Security Savings Bank, F.S.B.",Olathe,KS,30898,Simmons First National Bank,15-Oct-10,20-Aug-12
Shoreline Bank,Shoreline,WA,35250,GBC International Bank,1-Oct-10,20-Aug-12
Wakulla Bank,Crawfordville,FL,21777,Centennial Bank,1-Oct-10,21-Mar-14
North County Bank,Arlington,WA,35053,Whidbey Island Bank,24-Sep-10,12-Apr-16
Haven Trust Bank Florida,Ponte Vedra Beach,FL,58308,First Southern Bank,24-Sep-10,11-Jul-16
Maritime Savings Bank,West Allis,WI,28612,"North Shore Bank, FSB",17-Sep-10,20-Aug-12
Bramble Savings Bank,Milford,OH,27808,Foundation Bank,17-Sep-10,20-Aug-12
The Peoples Bank,Winder,GA,182,Community & Southern Bank,17-Sep-10,4-May-16
First Commerce Community Bank,Douglasville,GA,57448,Community & Southern Bank,17-Sep-10,4-May-16
Bank of Ellijay,Ellijay,GA,58197,Community & Southern Bank,17-Sep-10,6-Jun-16
ISN Bank,Cherry Hill,NJ,57107,Customers Bank,17-Sep-10,22-Aug-12
Horizon Bank,Bradenton,FL,35061,Bank of the Ozarks,10-Sep-10,21-Mar-14
Sonoma Valley Bank,Sonoma,CA,27259,Westamerica Bank,20-Aug-10,12-Sep-12
Los Padres Bank,Solvang,CA,32165,Pacific Western Bank,20-Aug-10,12-Sep-12
Butte Community Bank,Chico,CA,33219,"Rabobank, N.A.",20-Aug-10,12-Sep-12
Pacific State Bank,Stockton,CA,27090,"Rabobank, N.A.",20-Aug-10,12-Sep-12
ShoreBank,Chicago,IL,15640,Urban Partnership Bank,20-Aug-10,16-May-13
Imperial Savings and Loan Association,Martinsville,VA,31623,"River Community Bank, N.A.",20-Aug-10,24-Aug-12
Independent National Bank,Ocala,FL,27344,"CenterState Bank of Florida, N.A.",20-Aug-10,20-Oct-16
Community National Bank at Bartow,Bartow,FL,25266,"CenterState Bank of Florida, N.A.",20-Aug-10,11-Jul-16
Palos Bank and Trust Company,Palos Heights,IL,17599,First Midwest Bank,13-Aug-10,22-Aug-12
Ravenswood Bank,Chicago,IL,34231,Northbrook Bank & Trust Company,6-Aug-10,22-Aug-12
LibertyBank,Eugene,OR,31964,Home Federal Bank,30-Jul-10,22-Aug-12
The Cowlitz Bank,Longview,WA,22643,Heritage Bank,30-Jul-10,22-Aug-12
Coastal Community Bank,Panama City Beach,FL,9619,Centennial Bank,30-Jul-10,9-Feb-17
Bayside Savings Bank,Port Saint Joe,FL,57669,Centennial Bank,30-Jul-10,12-Dec-16
Northwest Bank & Trust,Acworth,GA,57658,State Bank and Trust Company,30-Jul-10,21-Sep-15
Home Valley Bank,Cave Junction,OR,23181,South Valley Bank & Trust,23-Jul-10,12-Sep-12
SouthwestUSA Bank,Las Vegas,NV,35434,Plaza Bank,23-Jul-10,22-Aug-12
Community Security Bank,New Prague,MN,34486,Roundbank,23-Jul-10,4-Feb-16
Thunder Bank,Sylvan Grove,KS,10506,The Bennington State Bank,23-Jul-10,13-Sep-12
Williamsburg First National Bank,Kingstree,SC,17837,"First Citizens Bank and Trust Company, Inc.",23-Jul-10,20-Oct-16
Crescent Bank and Trust Company,Jasper,GA,27559,Renasant Bank,23-Jul-10,21-Mar-14
Sterling Bank,Lantana,FL,32536,IBERIABANK,23-Jul-10,21-Mar-14
"Mainstreet Savings Bank, FSB",Hastings,MI,28136,Commercial Bank,16-Jul-10,13-Sep-12
Olde Cypress Community Bank,Clewiston,FL,28864,"CenterState Bank of Florida, N.A.",16-Jul-10,11-Jul-16
Turnberry Bank,Aventura,FL,32280,NAFH National Bank,16-Jul-10,12-Sep-16
Metro Bank of Dade County,Miami,FL,25172,NAFH National Bank,16-Jul-10,8-Aug-16
First National Bank of the South,Spartanburg,SC,35383,NAFH National Bank,16-Jul-10,21-Mar-14
Woodlands Bank,Bluffton,SC,32571,Bank of the Ozarks,16-Jul-10,21-Sep-15
Home National Bank,Blackwell,OK,11636,RCB Bank,9-Jul-10,12-Dec-16
USA Bank,Port Chester,NY,58072,New Century Bank,9-Jul-10,14-Sep-12
Ideal Federal Savings Bank,Baltimore,MD,32456,No Acquirer,9-Jul-10,8-May-15
Bay National Bank,Baltimore,MD,35462,"Bay Bank, FSB",9-Jul-10,15-Jan-13
High Desert State Bank,Albuquerque,NM,35279,First American Bank,25-Jun-10,14-Sep-12
First National Bank,Savannah,GA,34152,"The Savannah Bank, N.A.",25-Jun-10,21-Mar-14
Peninsula Bank,Englewood,FL,26563,"Premier American Bank, N.A.",25-Jun-10,21-Mar-14
Nevada Security Bank,Reno,NV,57110,Umpqua Bank,18-Jun-10,23-Aug-12
Washington First International Bank,Seattle,WA,32955,East West Bank,11-Jun-10,14-Sep-12
TierOne Bank,Lincoln,NE,29341,Great Western Bank,4-Jun-10,14-Sep-12
Arcola Homestead Savings Bank,Arcola,IL,31813,No Acquirer,4-Jun-10,8-May-15
First National Bank,Rosedale,MS,15814,The Jefferson Bank,4-Jun-10,21-Mar-14
Sun West Bank,Las Vegas,NV,34785,City National Bank,28-May-10,14-Sep-12
"Granite Community Bank, NA",Granite Bay,CA,57315,Tri Counties Bank,28-May-10,14-Sep-12
Bank of Florida - Tampa,Tampa,FL,57814,EverBank,28-May-10,8-Aug-16
Bank of Florida - Southwest,Naples,FL,35106,EverBank,28-May-10,8-Aug-16
Bank of Florida - Southeast,Fort Lauderdale,FL,57360,EverBank,28-May-10,8-Aug-16
Pinehurst Bank,Saint Paul,MN,57735,Coulee Bank,21-May-10,26-Oct-12
Midwest Bank and Trust Company,Elmwood Park,IL,18117,"FirstMerit Bank, N.A.",14-May-10,23-Aug-12
Southwest Community Bank,Springfield,MO,34255,Simmons First National Bank,14-May-10,4-Feb-16
New Liberty Bank,Plymouth,MI,35586,Bank of Ann Arbor,14-May-10,23-Aug-12
Satilla Community Bank,Saint Marys,GA,35114,Ameris Bank,14-May-10,21-Mar-14
1st Pacific Bank of California,San Diego,CA,35517,City National Bank,7-May-10,13-Dec-12
Towne Bank of Arizona,Mesa,AZ,57697,Commerce Bank of Arizona,7-May-10,23-Aug-12
Access Bank,Champlin,MN,16476,PrinsBank,7-May-10,5-Feb-15
The Bank of Bonifay,Bonifay,FL,14246,First Federal Bank of Florida,7-May-10,5-Nov-12
Frontier Bank,Everett,WA,22710,"Union Bank, N.A.",30-Apr-10,15-Jan-13
BC National Banks,Butler,MO,17792,Community First Bank,30-Apr-10,23-Aug-12
Champion Bank,Creve Coeur,MO,58362,BankLiberty,30-Apr-10,6-Jun-16
CF Bancorp,Port Huron,MI,30005,First Michigan Bank,30-Apr-10,13-Apr-16
Westernbank Puerto Rico,Mayaguez,PR,31027,Banco Popular de Puerto Rico,30-Apr-10,21-Mar-14
R-G Premier Bank of Puerto Rico,Hato Rey,PR,32185,Scotiabank de Puerto Rico,30-Apr-10,5-Aug-15
Eurobank,San Juan,PR,27150,Oriental Bank and Trust,30-Apr-10,21-Mar-14
Wheatland Bank,Naperville,IL,58429,Wheaton Bank & Trust,23-Apr-10,23-Aug-12
Peotone Bank and Trust Company,Peotone,IL,10888,First Midwest Bank,23-Apr-10,23-Aug-12
Lincoln Park Savings Bank,Chicago,IL,30600,Northbrook Bank & Trust Company,23-Apr-10,23-Aug-12
New Century Bank,Chicago,IL,34821,"MB Financial Bank, N.A.",23-Apr-10,23-Aug-12
Citizens Bank and Trust Company of Chicago,Chicago,IL,34658,Republic Bank of Chicago,23-Apr-10,5-Jun-14
Broadway Bank,Chicago,IL,22853,"MB Financial Bank, N.A.",23-Apr-10,23-Aug-12
"Amcore Bank, National Association",Rockford,IL,3735,Harris N.A.,23-Apr-10,23-Aug-12
City Bank,Lynnwood,WA,21521,Whidbey Island Bank,16-Apr-10,14-Sep-12
Tamalpais Bank,San Rafael,CA,33493,"Union Bank, N.A.",16-Apr-10,23-Aug-12
Innovative Bank,Oakland,CA,23876,Center Bank,16-Apr-10,23-Aug-12
Butler Bank,Lowell,MA,26619,People's United Bank,16-Apr-10,23-Aug-12
Riverside National Bank of Florida,Fort Pierce,FL,24067,"TD Bank, N.A.",16-Apr-10,21-Mar-14
AmericanFirst Bank,Clermont,FL,57724,"TD Bank, N.A.",16-Apr-10,21-Mar-14
First Federal Bank of North Florida,Palatka,FL,28886,"TD Bank, N.A.",16-Apr-10,21-Mar-14
Lakeside Community Bank,Sterling Heights,MI,34878,No Acquirer,16-Apr-10,23-Aug-12
Beach First National Bank,Myrtle Beach,SC,34242,Bank of North Carolina,9-Apr-10,21-Mar-14
Desert Hills Bank,Phoenix,AZ,57060,New York Community Bank,26-Mar-10,23-Aug-12
Unity National Bank,Cartersville,GA,34678,Bank of the Ozarks,26-Mar-10,21-Sep-15
Key West Bank,Key West,FL,34684,Centennial Bank,26-Mar-10,9-Feb-17
McIntosh Commercial Bank,Carrollton,GA,57399,CharterBank,26-Mar-10,11-Jul-16
State Bank of Aurora,Aurora,MN,8221,Northern State Bank,19-Mar-10,8-Aug-16
First Lowndes Bank,Fort Deposit,AL,24957,First Citizens Bank,19-Mar-10,21-Mar-14
Bank of Hiawassee,Hiawassee,GA,10054,Citizens South Bank,19-Mar-10,21-Mar-14
Appalachian Community Bank,Ellijay,GA,33989,Community & Southern Bank,19-Mar-10,21-Mar-14
Advanta Bank Corp.,Draper,UT,33535,No Acquirer,19-Mar-10,31-Mar-16
Century Security Bank,Duluth,GA,58104,Bank of Upson,19-Mar-10,13-Apr-16
American National Bank,Parma,OH,18806,The National Bank and Trust Company,19-Mar-10,21-Sep-15
Statewide Bank,Covington,LA,29561,Home Bank,12-Mar-10,23-Aug-12
Old Southern Bank,Orlando,FL,58182,Centennial Bank,12-Mar-10,9-Feb-17
The Park Avenue Bank,New York,NY,27096,Valley National Bank,12-Mar-10,23-Aug-12
LibertyPointe Bank,New York,NY,58071,Valley National Bank,11-Mar-10,23-Aug-12
Centennial Bank,Ogden,UT,34430,No Acquirer,5-Mar-10,14-Sep-12
Waterfield Bank,Germantown,MD,34976,No Acquirer,5-Mar-10,23-Aug-12
Bank of Illinois,Normal,IL,9268,Heartland Bank and Trust Company,5-Mar-10,23-Aug-12
Sun American Bank,Boca Raton,FL,27126,First-Citizens Bank & Trust Company,5-Mar-10,21-Mar-14
Rainier Pacific Bank,Tacoma,WA,38129,Umpqua Bank,26-Feb-10,23-Aug-12
Carson River Community Bank,Carson City,NV,58352,Heritage Bank of Nevada,26-Feb-10,15-Jan-13
"La Jolla Bank, FSB",La Jolla,CA,32423,"OneWest Bank, FSB",19-Feb-10,24-Aug-12
George Washington Savings Bank,Orland Park,IL,29952,"FirstMerit Bank, N.A.",19-Feb-10,24-Aug-12
The La Coste National Bank,La Coste,TX,3287,Community National Bank,19-Feb-10,19-Aug-14
Marco Community Bank,Marco Island,FL,57586,Mutual of Omaha Bank,19-Feb-10,21-Mar-14
1st American State Bank of Minnesota,Hancock,MN,15448,"Community Development Bank, FSB",5-Feb-10,1-Nov-13
American Marine Bank,Bainbridge Island,WA,16730,Columbia State Bank,29-Jan-10,24-Aug-12
First Regional Bank,Los Angeles,CA,23011,First-Citizens Bank & Trust Company,29-Jan-10,4-Mar-16
Community Bank and Trust,Cornelia,GA,5702,SCBT National Association,29-Jan-10,13-Apr-16
"Marshall Bank, N.A.",Hallock,MN,16133,United Valley Bank,29-Jan-10,23-Aug-12
Florida Community Bank,Immokalee,FL,5672,"Premier American Bank, N.A.",29-Jan-10,21-Mar-14
First National Bank of Georgia,Carrollton,GA,16480,Community & Southern Bank,29-Jan-10,21-Mar-14
Columbia River Bank,The Dalles,OR,22469,Columbia State Bank,22-Jan-10,14-Sep-12
Evergreen Bank,Seattle,WA,20501,Umpqua Bank,22-Jan-10,15-Jan-13
Charter Bank,Santa Fe,NM,32498,Charter Bank,22-Jan-10,23-Aug-12
Bank of Leeton,Leeton,MO,8265,"Sunflower Bank, N.A.",22-Jan-10,15-Jan-13
Premier American Bank,Miami,FL,57147,"Premier American Bank, N.A.",22-Jan-10,21-Sep-15
Barnes Banking Company,Kaysville,UT,1252,No Acquirer,15-Jan-10,23-Aug-12
St. Stephen State Bank,St. Stephen,MN,17522,First State Bank of St. Joseph,15-Jan-10,8-Aug-16
Town Community Bank & Trust,Antioch,IL,34705,First American Bank,15-Jan-10,23-Aug-12
Horizon Bank,Bellingham,WA,22977,Washington Federal Savings and Loan Association,8-Jan-10,23-Aug-12
"First Federal Bank of California, F.S.B.",Santa Monica,CA,28536,"OneWest Bank, FSB",18-Dec-09,23-Aug-12
Imperial Capital Bank,La Jolla,CA,26348,City National Bank,18-Dec-09,5-Sep-12
Independent Bankers' Bank,Springfield,IL,26820,The Independent BankersBank (TIB),18-Dec-09,23-Aug-12
New South Federal Savings Bank,Irondale,AL,32276,Beal Bank,18-Dec-09,23-Aug-12
Citizens State Bank,New Baltimore,MI,1006,No Acquirer,18-Dec-09,21-Mar-14
Peoples First Community Bank,Panama City,FL,32167,Hancock Bank,18-Dec-09,5-Nov-12
RockBridge Commercial Bank,Atlanta,GA,58315,No Acquirer,18-Dec-09,21-Mar-14
SolutionsBank,Overland Park,KS,4731,Arvest Bank,11-Dec-09,19-Jul-16
"Valley Capital Bank, N.A.",Mesa,AZ,58399,Enterprise Bank & Trust,11-Dec-09,20-Oct-16
"Republic Federal Bank, N.A.",Miami,FL,22846,1st United Bank,11-Dec-09,21-Mar-14
Greater Atlantic Bank,Reston,VA,32583,Sonabank,4-Dec-09,21-Mar-14
Benchmark Bank,Aurora,IL,10440,"MB Financial Bank, N.A.",4-Dec-09,23-Aug-12
AmTrust Bank,Cleveland,OH,29776,New York Community Bank,4-Dec-09,21-Mar-14
The Tattnall Bank,Reidsville,GA,12080,Heritage Bank of the South,4-Dec-09,21-Mar-14
First Security National Bank,Norcross,GA,26290,State Bank and Trust Company,4-Dec-09,17-Oct-15
The Buckhead Community Bank,Atlanta,GA,34663,State Bank and Trust Company,4-Dec-09,21-Mar-14
Commerce Bank of Southwest Florida,Fort Myers,FL,58016,Central Bank,20-Nov-09,21-Mar-14
Pacific Coast National Bank,San Clemente,CA,57914,Sunwest Bank,13-Nov-09,10-Apr-17
Orion Bank,Naples,FL,22427,IBERIABANK,13-Nov-09,21-Mar-14
"Century Bank, F.S.B.",Sarasota,FL,32267,IBERIABANK,13-Nov-09,21-Mar-14
United Commercial Bank,San Francisco,CA,32469,East West Bank,6-Nov-09,5-Nov-12
Gateway Bank of St. Louis,St. Louis,MO,19450,Central Bank of Kansas City,6-Nov-09,22-Aug-12
Prosperan Bank,Oakdale,MN,35074,"Alerus Financial, N.A.",6-Nov-09,22-Aug-12
Home Federal Savings Bank,Detroit,MI,30329,Liberty Bank and Trust Company,6-Nov-09,22-Aug-12
United Security Bank,Sparta,GA,22286,Ameris Bank,6-Nov-09,21-Mar-14
North Houston Bank,Houston,TX,18776,U.S. Bank N.A.,30-Oct-09,22-Aug-12
Madisonville State Bank,Madisonville,TX,33782,U.S. Bank N.A.,30-Oct-09,22-Aug-12
Citizens National Bank,Teague,TX,25222,U.S. Bank N.A.,30-Oct-09,22-Aug-12
Park National Bank,Chicago,IL,11677,U.S. Bank N.A.,30-Oct-09,22-Aug-12
Pacific National Bank,San Francisco,CA,30006,U.S. Bank N.A.,30-Oct-09,22-Aug-12
California National Bank,Los Angeles,CA,34659,U.S. Bank N.A.,30-Oct-09,5-Sep-12
San Diego National Bank,San Diego,CA,23594,U.S. Bank N.A.,30-Oct-09,22-Aug-12
Community Bank of Lemont,Lemont,IL,35291,U.S. Bank N.A.,30-Oct-09,15-Jan-13
"Bank USA, N.A.",Phoenix,AZ,32218,U.S. Bank N.A.,30-Oct-09,22-Aug-12
First DuPage Bank,Westmont,IL,35038,First Midwest Bank,23-Oct-09,22-Aug-12
Riverview Community Bank,Otsego,MN,57525,Central Bank,23-Oct-09,22-Aug-12
Bank of Elmwood,Racine,WI,18321,Tri City National Bank,23-Oct-09,22-Aug-12
Flagship National Bank,Bradenton,FL,35044,First Federal Bank of Florida,23-Oct-09,5-Feb-15
Hillcrest Bank Florida,Naples,FL,58336,Stonegate Bank,23-Oct-09,22-Aug-12
American United Bank,Lawrenceville,GA,57794,Ameris Bank,23-Oct-09,5-Sep-12
Partners Bank,Naples,FL,57959,Stonegate Bank,23-Oct-09,5-Feb-15
San Joaquin Bank,Bakersfield,CA,23266,Citizens Business Bank,16-Oct-09,22-Aug-12
Southern Colorado National Bank,Pueblo,CO,57263,Legacy Bank,2-Oct-09,12-Dec-16
Jennings State Bank,Spring Grove,MN,11416,Central Bank,2-Oct-09,21-Aug-12
Warren Bank,Warren,MI,34824,The Huntington National Bank,2-Oct-09,21-Aug-12
Georgian Bank,Atlanta,GA,57151,"First Citizens Bank and Trust Company, Inc.",25-Sep-09,21-Aug-12
"Irwin Union Bank, F.S.B.",Louisville,KY,57068,"First Financial Bank, N.A.",18-Sep-09,5-Sep-12
Irwin Union Bank and Trust Company,Columbus,IN,10100,"First Financial Bank, N.A.",18-Sep-09,21-Aug-12
Venture Bank,Lacey,WA,22868,First-Citizens Bank & Trust Company,11-Sep-09,21-Aug-12
Brickwell Community Bank,Woodbury,MN,57736,CorTrust Bank N.A.,11-Sep-09,20-Oct-16
"Corus Bank, N.A.",Chicago,IL,13693,"MB Financial Bank, N.A.",11-Sep-09,21-Aug-12
First State Bank,Flagstaff,AZ,34875,Sunwest Bank,4-Sep-09,5-Feb-15
Platinum Community Bank,Rolling Meadows,IL,35030,No Acquirer,4-Sep-09,21-Aug-12
Vantus Bank,Sioux City,IA,27732,Great Southern Bank,4-Sep-09,21-Aug-12
InBank,Oak Forest,IL,20203,"MB Financial Bank, N.A.",4-Sep-09,17-Oct-15
First Bank of Kansas City,Kansas City,MO,25231,Great American Bank,4-Sep-09,21-Aug-12
Affinity Bank,Ventura,CA,27197,Pacific Western Bank,28-Aug-09,21-Aug-12
Mainstreet Bank,Forest Lake,MN,1909,Central Bank,28-Aug-09,21-Aug-12
Bradford Bank,Baltimore,MD,28312,Manufacturers and Traders Trust Company (M&T Bank),28-Aug-09,15-Jan-13
Guaranty Bank,Austin,TX,32618,BBVA Compass,21-Aug-09,21-Aug-12
CapitalSouth Bank,Birmingham,AL,22130,IBERIABANK,21-Aug-09,15-Jan-13
First Coweta Bank,Newnan,GA,57702,United Bank,21-Aug-09,7-Dec-15
ebank,Atlanta,GA,34682,"Stearns Bank, N.A.",21-Aug-09,21-Aug-12
Community Bank of Nevada,Las Vegas,NV,34043,No Acquirer,14-Aug-09,21-Aug-12
Community Bank of Arizona,Phoenix,AZ,57645,MidFirst Bank,14-Aug-09,21-Aug-12
"Union Bank, National Association",Gilbert,AZ,34485,MidFirst Bank,14-Aug-09,21-Aug-12
Colonial Bank,Montgomery,AL,9609,"Branch Banking & Trust Company, (BB&T)",14-Aug-09,12-Jun-14
Dwelling House Savings and Loan Association,Pittsburgh,PA,31559,"PNC Bank, N.A.",14-Aug-09,15-Jan-13
Community First Bank,Prineville,OR,23268,Home Federal Bank,7-Aug-09,15-Jan-13
Community National Bank of Sarasota County,Venice,FL,27183,"Stearns Bank, N.A.",7-Aug-09,20-Aug-12
First State Bank,Sarasota,FL,27364,"Stearns Bank, N.A.",7-Aug-09,20-Aug-12
Mutual Bank,Harvey,IL,18659,United Central Bank,31-Jul-09,20-Aug-12
First BankAmericano,Elizabeth,NJ,34270,Crown Bank,31-Jul-09,20-Aug-12
Peoples Community Bank,West Chester,OH,32288,"First Financial Bank, N.A.",31-Jul-09,20-Aug-12
Integrity Bank,Jupiter,FL,57604,Stonegate Bank,31-Jul-09,20-Aug-12
First State Bank of Altus,Altus,OK,9873,Herring Bank,31-Jul-09,20-Aug-12
Security Bank of Jones County,Gray,GA,8486,State Bank and Trust Company,24-Jul-09,20-Aug-12
Security Bank of Houston County,Perry,GA,27048,State Bank and Trust Company,24-Jul-09,17-Oct-15
Security Bank of Bibb County,Macon,GA,27367,State Bank and Trust Company,24-Jul-09,20-Aug-12
Security Bank of North Metro,Woodstock,GA,57105,State Bank and Trust Company,24-Jul-09,6-Jan-16
Security Bank of North Fulton,Alpharetta,GA,57430,State Bank and Trust Company,24-Jul-09,20-Aug-12
Security Bank of Gwinnett County,Suwanee,GA,57346,State Bank and Trust Company,24-Jul-09,20-Aug-12
Waterford Village Bank,Williamsville,NY,58065,"Evans Bank, N.A.",24-Jul-09,1-Nov-13
Temecula Valley Bank,Temecula,CA,34341,First-Citizens Bank & Trust Company,17-Jul-09,20-Oct-16
Vineyard Bank,Rancho Cucamonga,CA,23556,California Bank & Trust,17-Jul-09,20-Aug-12
BankFirst,Sioux Falls,SD,34103,"Alerus Financial, N.A.",17-Jul-09,20-Aug-12
First Piedmont Bank,Winder,GA,34594,First American Bank and Trust Company,17-Jul-09,8-Aug-16
Bank of Wyoming,Thermopolis,WY,22754,Central Bank & Trust,10-Jul-09,20-Aug-12
Founders Bank,Worth,IL,18390,The PrivateBank and Trust Company,2-Jul-09,20-Aug-12
Millennium State Bank of Texas,Dallas,TX,57667,State Bank of Texas,2-Jul-09,26-Oct-12
First National Bank of Danville,Danville,IL,3644,"First Financial Bank, N.A.",2-Jul-09,20-Aug-12
Elizabeth State Bank,Elizabeth,IL,9262,Galena State Bank and Trust Company,2-Jul-09,20-Aug-12
Rock River Bank,Oregon,IL,15302,The Harvard State Bank,2-Jul-09,20-Aug-12
First State Bank of Winchester,Winchester,IL,11710,The First National Bank of Beardstown,2-Jul-09,20-Aug-12
John Warner Bank,Clinton,IL,12093,State Bank of Lincoln,2-Jul-09,20-Aug-12
Mirae Bank,Los Angeles,CA,57332,Wilshire State Bank,26-Jun-09,20-Aug-12
MetroPacific Bank,Irvine,CA,57893,Sunwest Bank,26-Jun-09,5-Feb-15
Horizon Bank,Pine City,MN,9744,"Stearns Bank, N.A.",26-Jun-09,5-Feb-15
Neighborhood Community Bank,Newnan,GA,35285,CharterBank,26-Jun-09,7-Dec-15
Community Bank of West Georgia,Villa Rica,GA,57436,No Acquirer,26-Jun-09,17-Aug-12
First National Bank of Anthony,Anthony,KS,4614,Bank of Kansas,19-Jun-09,21-Sep-15
Cooperative Bank,Wilmington,NC,27837,First Bank,19-Jun-09,17-Aug-12
Southern Community Bank,Fayetteville,GA,35251,United Community Bank,19-Jun-09,21-Sep-15
Bank of Lincolnwood,Lincolnwood,IL,17309,Republic Bank of Chicago,5-Jun-09,17-Aug-12
Citizens National Bank,Macomb,IL,5757,Morton Community Bank,22-May-09,4-Sep-12
Strategic Capital Bank,Champaign,IL,35175,Midland States Bank,22-May-09,4-Sep-12
"BankUnited, FSB",Coral Gables,FL,32247,BankUnited,21-May-09,17-Aug-12
Westsound Bank,Bremerton,WA,34843,Kitsap Bank,8-May-09,4-Sep-12
America West Bank,Layton,UT,35461,Cache Valley Bank,1-May-09,17-Aug-12
Citizens Community Bank,Ridgewood,NJ,57563,North Jersey Community Bank,1-May-09,4-Sep-12
"Silverton Bank, NA",Atlanta,GA,26535,No Acquirer,1-May-09,17-Aug-12
First Bank of Idaho,Ketchum,ID,34396,"U.S. Bank, N.A.",24-Apr-09,17-Aug-12
First Bank of Beverly Hills,Calabasas,CA,32069,No Acquirer,24-Apr-09,4-Sep-12
Michigan Heritage Bank,Farmington Hills,MI,34369,Level One Bank,24-Apr-09,17-Aug-12
American Southern Bank,Kennesaw,GA,57943,Bank of North Georgia,24-Apr-09,17-Aug-12
Great Basin Bank of Nevada,Elko,NV,33824,Nevada State Bank,17-Apr-09,4-Sep-12
American Sterling Bank,Sugar Creek,MO,8266,Metcalf Bank,17-Apr-09,31-Aug-12
New Frontier Bank,Greeley,CO,34881,No Acquirer,10-Apr-09,4-Sep-12
Cape Fear Bank,Wilmington,NC,34639,First Federal Savings and Loan Association,10-Apr-09,10-Apr-17
Omni National Bank,Atlanta,GA,22238,No Acquirer,27-Mar-09,17-Aug-12
"TeamBank, NA",Paola,KS,4754,Great Southern Bank,20-Mar-09,12-Sep-16
Colorado National Bank,Colorado Springs,CO,18896,Herring Bank,20-Mar-09,12-Dec-16
FirstCity Bank,Stockbridge,GA,18243,No Acquirer,20-Mar-09,17-Aug-12
Freedom Bank of Georgia,Commerce,GA,57558,Northeast Georgia Bank,6-Mar-09,17-Aug-12
Security Savings Bank,Henderson,NV,34820,Bank of Nevada,27-Feb-09,7-Sep-12
Heritage Community Bank,Glenwood,IL,20078,"MB Financial Bank, N.A.",27-Feb-09,17-Aug-12
Silver Falls Bank,Silverton,OR,35399,Citizens Bank,20-Feb-09,17-Aug-12
Pinnacle Bank of Oregon,Beaverton,OR,57342,Washington Trust Bank of Spokane,13-Feb-09,7-Dec-15
Corn Belt Bank & Trust Co.,Pittsfield,IL,16500,The Carlinville National Bank,13-Feb-09,17-Aug-12
Riverside Bank of the Gulf Coast,Cape Coral,FL,34563,TIB Bank,13-Feb-09,17-Aug-12
Sherman County Bank,Loup City,NE,5431,Heritage Bank,13-Feb-09,17-Aug-12
County Bank,Merced,CA,22574,Westamerica Bank,6-Feb-09,4-Sep-12
Alliance Bank,Culver City,CA,23124,California Bank & Trust,6-Feb-09,16-Aug-12
FirstBank Financial Services,McDonough,GA,57017,Regions Bank,6-Feb-09,16-Aug-12
Ocala National Bank,Ocala,FL,26538,"CenterState Bank of Florida, N.A.",30-Jan-09,4-Sep-12
Suburban FSB,Crofton,MD,30763,Bank of Essex,30-Jan-09,4-Feb-16
MagnetBank,Salt Lake City,UT,58001,No Acquirer,30-Jan-09,16-Aug-12
1st Centennial Bank,Redlands,CA,33025,First California Bank,23-Jan-09,13-Apr-16
Bank of Clark County,Vancouver,WA,34959,Umpqua Bank,16-Jan-09,16-Aug-12
National Bank of Commerce,Berkeley,IL,19733,Republic Bank of Chicago,16-Jan-09,16-Aug-12
Sanderson State Bank,Sanderson,TX,11568,The Pecos County State Bank,12-Dec-08,25-Oct-13
Haven Trust Bank,Duluth,GA,35379,"Branch Banking & Trust Company, (BB&T)",12-Dec-08,16-Aug-12
First Georgia Community Bank,Jackson,GA,34301,United Bank,5-Dec-08,16-Aug-12
PFF Bank & Trust,Pomona,CA,28344,"U.S. Bank, N.A.",21-Nov-08,4-Jan-13
Downey Savings & Loan,Newport Beach,CA,30968,"U.S. Bank, N.A.",21-Nov-08,4-Jan-13
Community Bank,Loganville,GA,16490,Bank of Essex,21-Nov-08,4-Sep-12
Security Pacific Bank,Los Angeles,CA,23595,Pacific Western Bank,7-Nov-08,28-Aug-12
"Franklin Bank, SSB",Houston,TX,26870,Prosperity Bank,7-Nov-08,16-Aug-12
Freedom Bank,Bradenton,FL,57930,Fifth Third Bank,31-Oct-08,16-Aug-12
Alpha Bank & Trust,Alpharetta,GA,58241,"Stearns Bank, N.A.",24-Oct-08,16-Aug-12
Meridian Bank,Eldred,IL,13789,National Bank,10-Oct-08,31-May-12
Main Street Bank,Northville,MI,57654,Monroe Bank & Trust,10-Oct-08,1-Aug-13
Washington Mutual Bank (Including its subsidiary Washington Mutual Bank FSB),Henderson,NV,32633,JP Morgan Chase Bank,25-Sep-08,4-Aug-15
Ameribank,Northfork,WV,6782,"The Citizens Savings Bank, Pioneer Community Bank, Inc.",19-Sep-08,21-Sep-15
Silver State Bank,Henderson,NV,34194,Nevada State Bank,5-Sep-08,25-Oct-13
Integrity Bank,Alpharetta,GA,35469,Regions Bank,29-Aug-08,16-Aug-12
Columbian Bank & Trust,Topeka,KS,22728,Citizens Bank & Trust,22-Aug-08,26-Mar-15
First Priority Bank,Bradenton,FL,57523,SunTrust Bank,1-Aug-08,12-Dec-16
"First Heritage Bank, NA",Newport Beach,CA,57961,Mutual of Omaha Bank,25-Jul-08,12-Sep-16
First National Bank of Nevada,Reno,NV,27011,Mutual of Omaha Bank,25-Jul-08,28-Aug-12
IndyMac Bank,Pasadena,CA,29730,"OneWest Bank, FSB",11-Jul-08,22-Apr-15
"First Integrity Bank, NA",Staples,MN,12736,First International Bank and Trust,30-May-08,20-Oct-16
"ANB Financial, NA",Bentonville,AR,33901,Pulaski Bank and Trust Company,9-May-08,28-Aug-12
Hume Bank,Hume,MO,1971,Security Bank,7-Mar-08,28-Aug-12
Douglass National Bank,Kansas City,MO,24660,Liberty Bank and Trust Company,25-Jan-08,26-Oct-12
Miami Valley Bank,Lakeview,OH,16848,The Citizens Banking Company,4-Oct-07,12-Sep-16
NetBank,Alpharetta,GA,32575,ING DIRECT,28-Sep-07,28-Aug-12
Metropolitan Savings Bank,Pittsburgh,PA,35353,Allegheny Valley Bank of Pittsburgh,2-Feb-07,27-Oct-10
Bank of Ephraim,Ephraim,UT,1249,Far West Bank,25-Jun-04,9-Apr-08
Reliance Bank,White Plains,NY,26778,Union State Bank,19-Mar-04,9-Apr-08
Guaranty National Bank of Tallahassee,Tallahassee,FL,26838,Hancock Bank of Florida,12-Mar-04,5-Jun-12
Dollar Savings Bank,Newark,NJ,31330,No Acquirer,14-Feb-04,9-Apr-08
Pulaski Savings Bank,Philadelphia,PA,27203,Earthstar Bank,14-Nov-03,22-Jul-05
First National Bank of Blanchardville,Blanchardville,WI,11639,The Park Bank,9-May-03,5-Jun-12
Southern Pacific Bank,Torrance,CA,27094,Beal Bank,7-Feb-03,20-Oct-08
Farmers Bank of Cheneyville,Cheneyville,LA,16445,Sabine State Bank & Trust,17-Dec-02,20-Oct-04
Bank of Alamo,Alamo,TN,9961,No Acquirer,8-Nov-02,18-Mar-05
AmTrade International Bank,Atlanta,GA,33784,No Acquirer,30-Sep-02,11-Sep-06
Connecticut Bank of Commerce,Stamford,CT,19183,Hudson United Bank,26-Jun-02,14-Feb-12
New Century Bank,Shelby Township,MI,34979,No Acquirer,28-Mar-02,18-Mar-05
Net 1st National Bank,Boca Raton,FL,26652,Bank Leumi USA,1-Mar-02,9-Apr-08
"NextBank, NA",Phoenix,AZ,22314,No Acquirer,7-Feb-02,5-Feb-15
Oakwood Deposit Bank Co.,Oakwood,OH,8966,The State Bank & Trust Company,1-Feb-02,25-Oct-12
Bank of Sierra Blanca,Sierra Blanca,TX,22002,The Security State Bank of Pecos,18-Jan-02,6-Nov-03
"Hamilton Bank, NA",Miami,FL,24382,Israel Discount Bank of New York,11-Jan-02,21-Sep-15
"Superior Bank, FSB",Hinsdale,IL,32646,"Superior Federal, FSB",27-Jul-01,19-Aug-14
Malta National Bank,Malta,OH,6629,North Valley Bank,3-May-01,18-Nov-02
First Alliance Bank & Trust Co.,Manchester,NH,34264,Southern New Hampshire Bank & Trust,2-Feb-01,18-Feb-03
National State Bank of Metropolis,Metropolis,IL,3815,Banterra Bank of Marion,14-Dec-00,17-Mar-05
Bank of Honolulu,Honolulu,HI,21029,Bank of the Orient,13-Oct-00,17-Mar-05
1 Bank Name City ST CERT Acquiring Institution Closing Date Updated Date
2 Fayette County Bank Saint Elmo IL 1802 United Fidelity Bank, fsb 26-May-17 1-Jun-17
3 Guaranty Bank, (d/b/a BestBank in Georgia & Michigan) Milwaukee WI 30003 First-Citizens Bank & Trust Company 5-May-17 1-Jun-17
4 First NBC Bank New Orleans LA 58302 Whitney Bank 28-Apr-17 23-May-17
5 Proficio Bank Cottonwood Heights UT 35495 Cache Valley Bank 3-Mar-17 18-May-17
6 Seaway Bank and Trust Company Chicago IL 19328 State Bank of Texas 27-Jan-17 18-May-17
7 Harvest Community Bank Pennsville NJ 34951 First-Citizens Bank & Trust Company 13-Jan-17 18-May-17
8 Allied Bank Mulberry AR 91 Today's Bank 23-Sep-16 17-Nov-16
9 The Woodbury Banking Company Woodbury GA 11297 United Bank 19-Aug-16 1-Jun-17
10 First CornerStone Bank King of Prussia PA 35312 First-Citizens Bank & Trust Company 6-May-16 6-Sep-16
11 Trust Company Bank Memphis TN 9956 The Bank of Fayette County 29-Apr-16 6-Sep-16
12 North Milwaukee State Bank Milwaukee WI 20364 First-Citizens Bank & Trust Company 11-Mar-16 13-Mar-17
13 Hometown National Bank Longview WA 35156 Twin City Bank 2-Oct-15 13-Apr-16
14 The Bank of Georgia Peachtree City GA 35259 Fidelity Bank 2-Oct-15 24-Oct-16
15 Premier Bank Denver CO 34112 United Fidelity Bank, fsb 10-Jul-15 17-Aug-16
16 Edgebrook Bank Chicago IL 57772 Republic Bank of Chicago 8-May-15 12-Jul-16
17 Doral Bank San Juan PR 32102 Banco Popular de Puerto Rico 27-Feb-15 13-May-15
18 Capitol City Bank & Trust Company Atlanta GA 33938 First-Citizens Bank & Trust Company 13-Feb-15 21-Apr-15
19 Highland Community Bank Chicago IL 20290 United Fidelity Bank, fsb 23-Jan-15 21-Apr-15
20 First National Bank of Crestview Crestview FL 17557 First NBC Bank 16-Jan-15 8-May-17
21 Northern Star Bank Mankato MN 34983 BankVista 19-Dec-14 6-Jan-16
22 Frontier Bank, FSB D/B/A El Paseo Bank Palm Desert CA 34738 Bank of Southern California, N.A. 7-Nov-14 10-Nov-16
23 The National Republic Bank of Chicago Chicago IL 916 State Bank of Texas 24-Oct-14 6-Jan-16
24 NBRS Financial Rising Sun MD 4862 Howard Bank 17-Oct-14 26-Mar-15
25 GreenChoice Bank, fsb Chicago IL 28462 Providence Bank, LLC 25-Jul-14 12-Dec-16
26 Eastside Commercial Bank Conyers GA 58125 Community & Southern Bank 18-Jul-14 11-Jul-16
27 The Freedom State Bank Freedom OK 12483 Alva State Bank & Trust Company 27-Jun-14 25-Mar-16
28 Valley Bank Fort Lauderdale FL 21793 Landmark Bank, National Association 20-Jun-14 29-Jun-15
29 Valley Bank Moline IL 10450 Great Southern Bank 20-Jun-14 26-Jun-15
30 Slavie Federal Savings Bank Bel Air MD 32368 Bay Bank, FSB 30-May-14 12-Dec-16
31 Columbia Savings Bank Cincinnati OH 32284 United Fidelity Bank, fsb 23-May-14 10-Nov-16
32 AztecAmerica Bank Berwyn IL 57866 Republic Bank of Chicago 16-May-14 20-Oct-16
33 Allendale County Bank Fairfax SC 15062 Palmetto State Bank 25-Apr-14 18-Jul-14
34 Vantage Point Bank Horsham PA 58531 First Choice Bank 28-Feb-14 3-Mar-15
35 Millennium Bank, National Association Sterling VA 35096 WashingtonFirst Bank 28-Feb-14 3-Mar-15
36 Syringa Bank Boise ID 34296 Sunwest Bank 31-Jan-14 12-Apr-16
37 The Bank of Union El Reno OK 17967 BancFirst 24-Jan-14 25-Mar-16
38 DuPage National Bank West Chicago IL 5732 Republic Bank of Chicago 17-Jan-14 20-Oct-16
39 Texas Community Bank, National Association The Woodlands TX 57431 Spirit of Texas Bank, SSB 13-Dec-13 29-Dec-14
40 Bank of Jackson County Graceville FL 14794 First Federal Bank of Florida 30-Oct-13 20-Oct-16
41 First National Bank also operating as The National Bank of El Paso Edinburg TX 14318 PlainsCapital Bank 13-Sep-13 27-May-15
42 The Community's Bank Bridgeport CT 57041 No Acquirer 13-Sep-13 7-Dec-15
43 Sunrise Bank of Arizona Phoenix AZ 34707 First Fidelity Bank, National Association 23-Aug-13 3-May-17
44 Community South Bank Parsons TN 19849 CB&S Bank, Inc. 23-Aug-13 12-Sep-14
45 Bank of Wausau Wausau WI 35016 Nicolet National Bank 9-Aug-13 24-Oct-13
46 First Community Bank of Southwest Florida (also operating as Community Bank of Cape Coral) Fort Myers FL 34943 C1 Bank 2-Aug-13 9-Feb-17
47 Mountain National Bank Sevierville TN 34789 First Tennessee Bank, National Association 7-Jun-13 4-Feb-16
48 1st Commerce Bank North Las Vegas NV 58358 Plaza Bank 6-Jun-13 12-Jul-13
49 Banks of Wisconsin d/b/a Bank of Kenosha Kenosha WI 35386 North Shore Bank, FSB 31-May-13 5-May-17
50 Central Arizona Bank Scottsdale AZ 34527 Western State Bank 14-May-13 7-Dec-15
51 Sunrise Bank Valdosta GA 58185 Synovus Bank 10-May-13 26-Jun-14
52 Pisgah Community Bank Asheville NC 58701 Capital Bank, N.A. 10-May-13 8-Aug-16
53 Douglas County Bank Douglasville GA 21649 Hamilton State Bank 26-Apr-13 25-Apr-14
54 Parkway Bank Lenoir NC 57158 CertusBank, National Association 26-Apr-13 20-Oct-16
55 Chipola Community Bank Marianna FL 58034 First Federal Bank of Florida 19-Apr-13 21-Sep-15
56 Heritage Bank of North Florida Orange Park FL 26680 FirstAtlantic Bank 19-Apr-13 8-Aug-16
57 First Federal Bank Lexington KY 29594 Your Community Bank 19-Apr-13 12-Dec-16
58 Gold Canyon Bank Gold Canyon AZ 58066 First Scottsdale Bank, National Association 5-Apr-13 7-Oct-15
59 Frontier Bank LaGrange GA 16431 HeritageBank of the South 8-Mar-13 2-Mar-16
60 Covenant Bank Chicago IL 22476 Liberty Bank and Trust Company 15-Feb-13 21-Sep-15
61 1st Regents Bank Andover MN 57157 First Minnesota Bank 18-Jan-13 12-Jul-16
62 Westside Community Bank University Place WA 33997 Sunwest Bank 11-Jan-13 8-Aug-16
63 Community Bank of the Ozarks Sunrise Beach MO 27331 Bank of Sullivan 14-Dec-12 4-Apr-14
64 Hometown Community Bank Braselton GA 57928 CertusBank, National Association 16-Nov-12 6-Jan-16
65 Citizens First National Bank Princeton IL 3731 Heartland Bank and Trust Company 2-Nov-12 22-Nov-13
66 Heritage Bank of Florida Lutz FL 35009 Centennial Bank 2-Nov-12 21-Mar-14
67 NOVA Bank Berwyn PA 27148 No Acquirer 26-Oct-12 24-Jan-13
68 Excel Bank Sedalia MO 19189 Simmons First National Bank 19-Oct-12 22-Oct-13
69 First East Side Savings Bank Tamarac FL 28144 Stearns Bank N.A. 19-Oct-12 6-Jan-16
70 GulfSouth Private Bank Destin FL 58073 SmartBank 19-Oct-12 21-Mar-14
71 First United Bank Crete IL 20685 Old Plank Trail Community Bank, National Association 28-Sep-12 1-Nov-13
72 Truman Bank St. Louis MO 27316 Simmons First National Bank 14-Sep-12 17-Dec-12
73 First Commercial Bank Bloomington MN 35246 Republic Bank & Trust Company 7-Sep-12 17-Dec-12
74 Waukegan Savings Bank Waukegan IL 28243 First Midwest Bank 3-Aug-12 7-Dec-15
75 Jasper Banking Company Jasper GA 16240 Stearns Bank N.A. 27-Jul-12 21-Mar-14
76 Second Federal Savings and Loan Association of Chicago Chicago IL 27986 Hinsdale Bank & Trust Company 20-Jul-12 14-Jan-13
77 Heartland Bank Leawood KS 1361 Metcalf Bank 20-Jul-12 30-Jul-13
78 First Cherokee State Bank Woodstock GA 32711 Community & Southern Bank 20-Jul-12 6-Jun-16
79 Georgia Trust Bank Buford GA 57847 Community & Southern Bank 20-Jul-12 21-Mar-14
80 The Royal Palm Bank of Florida Naples FL 57096 First National Bank of the Gulf Coast 20-Jul-12 21-Mar-14
81 Glasgow Savings Bank Glasgow MO 1056 Regional Missouri Bank 13-Jul-12 19-Aug-14
82 Montgomery Bank & Trust Ailey GA 19498 Ameris Bank 6-Jul-12 21-Mar-14
83 The Farmers Bank of Lynchburg Lynchburg TN 1690 Clayton Bank and Trust 15-Jun-12 8-Aug-16
84 Security Exchange Bank Marietta GA 35299 Fidelity Bank 15-Jun-12 21-Mar-14
85 Putnam State Bank Palatka FL 27405 Harbor Community Bank 15-Jun-12 21-Mar-14
86 Waccamaw Bank Whiteville NC 34515 First Community Bank 8-Jun-12 21-Mar-14
87 Farmers' and Traders' State Bank Shabbona IL 9257 First State Bank 8-Jun-12 10-Oct-12
88 Carolina Federal Savings Bank Charleston SC 35372 Bank of North Carolina 8-Jun-12 21-Mar-14
89 First Capital Bank Kingfisher OK 416 F & M Bank 8-Jun-12 5-Feb-15
90 Alabama Trust Bank, National Association Sylacauga AL 35224 Southern States Bank 18-May-12 21-Sep-15
91 Security Bank, National Association North Lauderdale FL 23156 Banesco USA 4-May-12 12-Apr-16
92 Palm Desert National Bank Palm Desert CA 23632 Pacific Premier Bank 27-Apr-12 7-Dec-15
93 Plantation Federal Bank Pawleys Island SC 32503 First Federal Bank 27-Apr-12 10-Nov-16
94 Inter Savings Bank, fsb D/B/A InterBank, fsb Maple Grove MN 31495 Great Southern Bank 27-Apr-12 17-May-13
95 HarVest Bank of Maryland Gaithersburg MD 57766 Sonabank 27-Apr-12 21-Sep-15
96 Bank of the Eastern Shore Cambridge MD 26759 No Acquirer 27-Apr-12 17-Oct-12
97 Fort Lee Federal Savings Bank, FSB Fort Lee NJ 35527 Alma Bank 20-Apr-12 17-May-13
98 Fidelity Bank Dearborn MI 33883 The Huntington National Bank 30-Mar-12 4-Feb-14
99 Premier Bank Wilmette IL 35419 International Bank of Chicago 23-Mar-12 17-Oct-12
100 Covenant Bank & Trust Rock Spring GA 58068 Stearns Bank, N.A. 23-Mar-12 21-Mar-14
101 New City Bank Chicago IL 57597 No Acquirer 9-Mar-12 29-Oct-12
102 Global Commerce Bank Doraville GA 34046 Metro City Bank 2-Mar-12 26-Jun-14
103 Home Savings of America Little Falls MN 29178 No Acquirer 24-Feb-12 17-Dec-12
104 Central Bank of Georgia Ellaville GA 5687 Ameris Bank 24-Feb-12 21-Mar-14
105 SCB Bank Shelbyville IN 29761 First Merchants Bank, National Association 10-Feb-12 19-Feb-15
106 Charter National Bank and Trust Hoffman Estates IL 23187 Barrington Bank & Trust Company, National Association 10-Feb-12 25-Mar-13
107 BankEast Knoxville TN 19869 U.S. Bank, N.A. 27-Jan-12 7-Dec-15
108 Patriot Bank Minnesota Forest Lake MN 34823 First Resource Bank 27-Jan-12 12-Sep-12
109 Tennessee Commerce Bank Franklin TN 35296 Republic Bank & Trust Company 27-Jan-12 21-Mar-14
110 First Guaranty Bank and Trust Company of Jacksonville Jacksonville FL 16579 CenterState Bank of Florida, N.A. 27-Jan-12 11-Jul-16
111 American Eagle Savings Bank Boothwyn PA 31581 Capital Bank, N.A. 20-Jan-12 25-Jan-13
112 The First State Bank Stockbridge GA 19252 Hamilton State Bank 20-Jan-12 21-Mar-14
113 Central Florida State Bank Belleview FL 57186 CenterState Bank of Florida, N.A. 20-Jan-12 6-Jun-16
114 Western National Bank Phoenix AZ 57917 Washington Federal 16-Dec-11 5-Feb-15
115 Premier Community Bank of the Emerald Coast Crestview FL 58343 Summit Bank 16-Dec-11 21-Mar-14
116 Central Progressive Bank Lacombe LA 19657 First NBC Bank 18-Nov-11 5-Feb-15
117 Polk County Bank Johnston IA 14194 Grinnell State Bank 18-Nov-11 15-Aug-12
118 Community Bank of Rockmart Rockmart GA 57860 Century Bank of Georgia 10-Nov-11 21-Mar-14
119 SunFirst Bank Saint George UT 57087 Cache Valley Bank 4-Nov-11 16-Nov-12
120 Mid City Bank, Inc. Omaha NE 19397 Premier Bank 4-Nov-11 15-Aug-12
121 All American Bank Des Plaines IL 57759 International Bank of Chicago 28-Oct-11 15-Aug-12
122 Community Banks of Colorado Greenwood Village CO 21132 Bank Midwest, N.A. 21-Oct-11 2-Jan-13
123 Community Capital Bank Jonesboro GA 57036 State Bank and Trust Company 21-Oct-11 6-Jan-16
124 Decatur First Bank Decatur GA 34392 Fidelity Bank 21-Oct-11 21-Mar-14
125 Old Harbor Bank Clearwater FL 57537 1st United Bank 21-Oct-11 21-Mar-14
126 Country Bank Aledo IL 35395 Blackhawk Bank & Trust 14-Oct-11 13-Apr-17
127 First State Bank Cranford NJ 58046 Northfield Bank 14-Oct-11 8-Nov-12
128 Blue Ridge Savings Bank, Inc. Asheville NC 32347 Bank of North Carolina 14-Oct-11 21-Mar-14
129 Piedmont Community Bank Gray GA 57256 State Bank and Trust Company 14-Oct-11 21-Mar-14
130 Sun Security Bank Ellington MO 20115 Great Southern Bank 7-Oct-11 8-May-17
131 The RiverBank Wyoming MN 10216 Central Bank 7-Oct-11 7-Nov-12
132 First International Bank Plano TX 33513 American First National Bank 30-Sep-11 5-Feb-15
133 Citizens Bank of Northern California Nevada City CA 33983 Tri Counties Bank 23-Sep-11 9-Oct-12
134 Bank of the Commonwealth Norfolk VA 20408 Southern Bank and Trust Company 23-Sep-11 9-Oct-12
135 The First National Bank of Florida Milton FL 25155 CharterBank 9-Sep-11 21-Mar-14
136 CreekSide Bank Woodstock GA 58226 Georgia Commerce Bank 2-Sep-11 21-Mar-14
137 Patriot Bank of Georgia Cumming GA 58273 Georgia Commerce Bank 2-Sep-11 21-Mar-14
138 First Choice Bank Geneva IL 57212 Inland Bank & Trust 19-Aug-11 5-Feb-15
139 First Southern National Bank Statesboro GA 57239 Heritage Bank of the South 19-Aug-11 2-Mar-16
140 Lydian Private Bank Palm Beach FL 35356 Sabadell United Bank, N.A. 19-Aug-11 21-Mar-14
141 Public Savings Bank Huntingdon Valley PA 34130 Capital Bank, N.A. 18-Aug-11 15-Aug-12
142 The First National Bank of Olathe Olathe KS 4744 Enterprise Bank & Trust 12-Aug-11 23-Aug-12
143 Bank of Whitman Colfax WA 22528 Columbia State Bank 5-Aug-11 16-Aug-12
144 Bank of Shorewood Shorewood IL 22637 Heartland Bank and Trust Company 5-Aug-11 20-Oct-16
145 Integra Bank National Association Evansville IN 4392 Old National Bank 29-Jul-11 16-Aug-12
146 BankMeridian, N.A. Columbia SC 58222 SCBT National Association 29-Jul-11 21-Mar-14
147 Virginia Business Bank Richmond VA 58283 Xenith Bank 29-Jul-11 9-Oct-12
148 Bank of Choice Greeley CO 2994 Bank Midwest, N.A. 22-Jul-11 12-Sep-12
149 LandMark Bank of Florida Sarasota FL 35244 American Momentum Bank 22-Jul-11 21-Mar-14
150 Southshore Community Bank Apollo Beach FL 58056 American Momentum Bank 22-Jul-11 5-Feb-15
151 Summit Bank Prescott AZ 57442 The Foothills Bank 15-Jul-11 19-Aug-14
152 First Peoples Bank Port St. Lucie FL 34870 Premier American Bank, N.A. 15-Jul-11 12-Jul-16
153 High Trust Bank Stockbridge GA 19554 Ameris Bank 15-Jul-11 21-Mar-14
154 One Georgia Bank Atlanta GA 58238 Ameris Bank 15-Jul-11 21-Mar-14
155 Signature Bank Windsor CO 57835 Points West Community Bank 8-Jul-11 26-Oct-12
156 Colorado Capital Bank Castle Rock CO 34522 First-Citizens Bank & Trust Company 8-Jul-11 10-Nov-16
157 First Chicago Bank & Trust Chicago IL 27935 Northbrook Bank & Trust Company 8-Jul-11 9-Sep-12
158 Mountain Heritage Bank Clayton GA 57593 First American Bank and Trust Company 24-Jun-11 9-Feb-17
159 First Commercial Bank of Tampa Bay Tampa FL 27583 Stonegate Bank 17-Jun-11 12-Sep-16
160 McIntosh State Bank Jackson GA 19237 Hamilton State Bank 17-Jun-11 21-Mar-14
161 Atlantic Bank and Trust Charleston SC 58420 First Citizens Bank and Trust Company, Inc. 3-Jun-11 21-Mar-14
162 First Heritage Bank Snohomish WA 23626 Columbia State Bank 27-May-11 28-Jan-13
163 Summit Bank Burlington WA 513 Columbia State Bank 20-May-11 22-Jan-13
164 First Georgia Banking Company Franklin GA 57647 CertusBank, National Association 20-May-11 21-Mar-14
165 Atlantic Southern Bank Macon GA 57213 CertusBank, National Association 20-May-11 21-Mar-14
166 Coastal Bank Cocoa Beach FL 34898 Florida Community Bank, a division of Premier American Bank, N.A. 6-May-11 21-Sep-15
167 Community Central Bank Mount Clemens MI 34234 Talmer Bank & Trust 29-Apr-11 13-Apr-17
168 The Park Avenue Bank Valdosta GA 19797 Bank of the Ozarks 29-Apr-11 21-Mar-14
169 First Choice Community Bank Dallas GA 58539 Bank of the Ozarks 29-Apr-11 21-Sep-15
170 Cortez Community Bank Brooksville FL 57625 Florida Community Bank, a division of Premier American Bank, N.A. 29-Apr-11 8-Aug-16
171 First National Bank of Central Florida Winter Park FL 26297 Florida Community Bank, a division of Premier American Bank, N.A. 29-Apr-11 4-May-16
172 Heritage Banking Group Carthage MS 14273 Trustmark National Bank 15-Apr-11 21-Mar-14
173 Rosemount National Bank Rosemount MN 24099 Central Bank 15-Apr-11 7-Dec-15
174 Superior Bank Birmingham AL 17750 Superior Bank, National Association 15-Apr-11 21-Mar-14
175 Nexity Bank Birmingham AL 19794 AloStar Bank of Commerce 15-Apr-11 21-Mar-14
176 New Horizons Bank East Ellijay GA 57705 Citizens South Bank 15-Apr-11 21-Mar-14
177 Bartow County Bank Cartersville GA 21495 Hamilton State Bank 15-Apr-11 21-Mar-14
178 Nevada Commerce Bank Las Vegas NV 35418 City National Bank 8-Apr-11 9-Sep-12
179 Western Springs National Bank and Trust Western Springs IL 10086 Heartland Bank and Trust Company 8-Apr-11 22-Jan-13
180 The Bank of Commerce Wood Dale IL 34292 Advantage National Bank Group 25-Mar-11 22-Jan-13
181 Legacy Bank Milwaukee WI 34818 Seaway Bank and Trust Company 11-Mar-11 12-Sep-12
182 First National Bank of Davis Davis OK 4077 The Pauls Valley National Bank 11-Mar-11 13-Apr-17
183 Valley Community Bank St. Charles IL 34187 First State Bank 25-Feb-11 5-Feb-15
184 San Luis Trust Bank, FSB San Luis Obispo CA 34783 First California Bank 18-Feb-11 12-Sep-16
185 Charter Oak Bank Napa CA 57855 Bank of Marin 18-Feb-11 12-Sep-12
186 Citizens Bank of Effingham Springfield GA 34601 Heritage Bank of the South 18-Feb-11 21-Mar-14
187 Habersham Bank Clarkesville GA 151 SCBT National Association 18-Feb-11 21-Mar-14
188 Canyon National Bank Palm Springs CA 34692 Pacific Premier Bank 11-Feb-11 19-Aug-14
189 Badger State Bank Cassville WI 13272 Royal Bank 11-Feb-11 12-Sep-12
190 Peoples State Bank Hamtramck MI 14939 First Michigan Bank 11-Feb-11 22-Jan-13
191 Sunshine State Community Bank Port Orange FL 35478 Premier American Bank, N.A. 11-Feb-11 8-Aug-16
192 Community First Bank Chicago Chicago IL 57948 Northbrook Bank & Trust Company 4-Feb-11 20-Aug-12
193 North Georgia Bank Watkinsville GA 35242 BankSouth 4-Feb-11 21-Mar-14
194 American Trust Bank Roswell GA 57432 Renasant Bank 4-Feb-11 21-Mar-14
195 First Community Bank Taos NM 12261 U.S. Bank, N.A. 28-Jan-11 12-Sep-12
196 FirsTier Bank Louisville CO 57646 No Acquirer 28-Jan-11 12-Sep-12
197 Evergreen State Bank Stoughton WI 5328 McFarland State Bank 28-Jan-11 12-Sep-12
198 The First State Bank Camargo OK 2303 Bank 7 28-Jan-11 12-Sep-12
199 United Western Bank Denver CO 31293 First-Citizens Bank & Trust Company 21-Jan-11 12-Sep-12
200 The Bank of Asheville Asheville NC 34516 First Bank 21-Jan-11 21-Mar-14
201 CommunitySouth Bank & Trust Easley SC 57868 CertusBank, National Association 21-Jan-11 6-Jun-16
202 Enterprise Banking Company McDonough GA 19758 No Acquirer 21-Jan-11 21-Mar-14
203 Oglethorpe Bank Brunswick GA 57440 Bank of the Ozarks 14-Jan-11 21-Mar-14
204 Legacy Bank Scottsdale AZ 57820 Enterprise Bank & Trust 7-Jan-11 12-Apr-16
205 First Commercial Bank of Florida Orlando FL 34965 First Southern Bank 7-Jan-11 6-Jun-16
206 Community National Bank Lino Lakes MN 23306 Farmers & Merchants Savings Bank 17-Dec-10 10-Nov-16
207 First Southern Bank Batesville AR 58052 Southern Bank 17-Dec-10 20-Aug-12
208 United Americas Bank, N.A. Atlanta GA 35065 State Bank and Trust Company 17-Dec-10 17-Oct-15
209 Appalachian Community Bank, FSB McCaysville GA 58495 Peoples Bank of East Tennessee 17-Dec-10 21-Mar-14
210 Chestatee State Bank Dawsonville GA 34578 Bank of the Ozarks 17-Dec-10 21-Sep-15
211 The Bank of Miami,N.A. Coral Gables FL 19040 1st United Bank 17-Dec-10 21-Mar-14
212 Earthstar Bank Southampton PA 35561 Polonia Bank 10-Dec-10 20-Aug-12
213 Paramount Bank Farmington Hills MI 34673 Level One Bank 10-Dec-10 21-Sep-15
214 First Banking Center Burlington WI 5287 First Michigan Bank 19-Nov-10 20-Aug-12
215 Allegiance Bank of North America Bala Cynwyd PA 35078 VIST Bank 19-Nov-10 20-Aug-12
216 Gulf State Community Bank Carrabelle FL 20340 Centennial Bank 19-Nov-10 12-Dec-16
217 Copper Star Bank Scottsdale AZ 35463 Stearns Bank, N.A. 12-Nov-10 20-Aug-12
218 Darby Bank & Trust Co. Vidalia GA 14580 Ameris Bank 12-Nov-10 21-Mar-14
219 Tifton Banking Company Tifton GA 57831 Ameris Bank 12-Nov-10 21-Mar-14
220 First Vietnamese American Bank Westminster CA 57885 Grandpoint Bank 5-Nov-10 12-Sep-12
221 Pierce Commercial Bank Tacoma WA 34411 Heritage Bank 5-Nov-10 19-Oct-15
222 Western Commercial Bank Woodland Hills CA 58087 First California Bank 5-Nov-10 12-Sep-16
223 K Bank Randallstown MD 31263 Manufacturers and Traders Trust Company (M&T Bank) 5-Nov-10 20-Aug-12
224 First Arizona Savings, A FSB Scottsdale AZ 32582 No Acquirer 22-Oct-10 20-Aug-12
225 Hillcrest Bank Overland Park KS 22173 Hillcrest Bank, N.A. 22-Oct-10 20-Aug-12
226 First Suburban National Bank Maywood IL 16089 Seaway Bank and Trust Company 22-Oct-10 20-Aug-12
227 The First National Bank of Barnesville Barnesville GA 2119 United Bank 22-Oct-10 17-Oct-15
228 The Gordon Bank Gordon GA 33904 Morris Bank 22-Oct-10 21-Mar-14
229 Progress Bank of Florida Tampa FL 32251 Bay Cities Bank 22-Oct-10 4-Feb-16
230 First Bank of Jacksonville Jacksonville FL 27573 Ameris Bank 22-Oct-10 21-Mar-14
231 Premier Bank Jefferson City MO 34016 Providence Bank 15-Oct-10 20-Aug-12
232 WestBridge Bank and Trust Company Chesterfield MO 58205 Midland States Bank 15-Oct-10 9-Feb-17
233 Security Savings Bank, F.S.B. Olathe KS 30898 Simmons First National Bank 15-Oct-10 20-Aug-12
234 Shoreline Bank Shoreline WA 35250 GBC International Bank 1-Oct-10 20-Aug-12
235 Wakulla Bank Crawfordville FL 21777 Centennial Bank 1-Oct-10 21-Mar-14
236 North County Bank Arlington WA 35053 Whidbey Island Bank 24-Sep-10 12-Apr-16
237 Haven Trust Bank Florida Ponte Vedra Beach FL 58308 First Southern Bank 24-Sep-10 11-Jul-16
238 Maritime Savings Bank West Allis WI 28612 North Shore Bank, FSB 17-Sep-10 20-Aug-12
239 Bramble Savings Bank Milford OH 27808 Foundation Bank 17-Sep-10 20-Aug-12
240 The Peoples Bank Winder GA 182 Community & Southern Bank 17-Sep-10 4-May-16
241 First Commerce Community Bank Douglasville GA 57448 Community & Southern Bank 17-Sep-10 4-May-16
242 Bank of Ellijay Ellijay GA 58197 Community & Southern Bank 17-Sep-10 6-Jun-16
243 ISN Bank Cherry Hill NJ 57107 Customers Bank 17-Sep-10 22-Aug-12
244 Horizon Bank Bradenton FL 35061 Bank of the Ozarks 10-Sep-10 21-Mar-14
245 Sonoma Valley Bank Sonoma CA 27259 Westamerica Bank 20-Aug-10 12-Sep-12
246 Los Padres Bank Solvang CA 32165 Pacific Western Bank 20-Aug-10 12-Sep-12
247 Butte Community Bank Chico CA 33219 Rabobank, N.A. 20-Aug-10 12-Sep-12
248 Pacific State Bank Stockton CA 27090 Rabobank, N.A. 20-Aug-10 12-Sep-12
249 ShoreBank Chicago IL 15640 Urban Partnership Bank 20-Aug-10 16-May-13
250 Imperial Savings and Loan Association Martinsville VA 31623 River Community Bank, N.A. 20-Aug-10 24-Aug-12
251 Independent National Bank Ocala FL 27344 CenterState Bank of Florida, N.A. 20-Aug-10 20-Oct-16
252 Community National Bank at Bartow Bartow FL 25266 CenterState Bank of Florida, N.A. 20-Aug-10 11-Jul-16
253 Palos Bank and Trust Company Palos Heights IL 17599 First Midwest Bank 13-Aug-10 22-Aug-12
254 Ravenswood Bank Chicago IL 34231 Northbrook Bank & Trust Company 6-Aug-10 22-Aug-12
255 LibertyBank Eugene OR 31964 Home Federal Bank 30-Jul-10 22-Aug-12
256 The Cowlitz Bank Longview WA 22643 Heritage Bank 30-Jul-10 22-Aug-12
257 Coastal Community Bank Panama City Beach FL 9619 Centennial Bank 30-Jul-10 9-Feb-17
258 Bayside Savings Bank Port Saint Joe FL 57669 Centennial Bank 30-Jul-10 12-Dec-16
259 Northwest Bank & Trust Acworth GA 57658 State Bank and Trust Company 30-Jul-10 21-Sep-15
260 Home Valley Bank Cave Junction OR 23181 South Valley Bank & Trust 23-Jul-10 12-Sep-12
261 SouthwestUSA Bank Las Vegas NV 35434 Plaza Bank 23-Jul-10 22-Aug-12
262 Community Security Bank New Prague MN 34486 Roundbank 23-Jul-10 4-Feb-16
263 Thunder Bank Sylvan Grove KS 10506 The Bennington State Bank 23-Jul-10 13-Sep-12
264 Williamsburg First National Bank Kingstree SC 17837 First Citizens Bank and Trust Company, Inc. 23-Jul-10 20-Oct-16
265 Crescent Bank and Trust Company Jasper GA 27559 Renasant Bank 23-Jul-10 21-Mar-14
266 Sterling Bank Lantana FL 32536 IBERIABANK 23-Jul-10 21-Mar-14
267 Mainstreet Savings Bank, FSB Hastings MI 28136 Commercial Bank 16-Jul-10 13-Sep-12
268 Olde Cypress Community Bank Clewiston FL 28864 CenterState Bank of Florida, N.A. 16-Jul-10 11-Jul-16
269 Turnberry Bank Aventura FL 32280 NAFH National Bank 16-Jul-10 12-Sep-16
270 Metro Bank of Dade County Miami FL 25172 NAFH National Bank 16-Jul-10 8-Aug-16
271 First National Bank of the South Spartanburg SC 35383 NAFH National Bank 16-Jul-10 21-Mar-14
272 Woodlands Bank Bluffton SC 32571 Bank of the Ozarks 16-Jul-10 21-Sep-15
273 Home National Bank Blackwell OK 11636 RCB Bank 9-Jul-10 12-Dec-16
274 USA Bank Port Chester NY 58072 New Century Bank 9-Jul-10 14-Sep-12
275 Ideal Federal Savings Bank Baltimore MD 32456 No Acquirer 9-Jul-10 8-May-15
276 Bay National Bank Baltimore MD 35462 Bay Bank, FSB 9-Jul-10 15-Jan-13
277 High Desert State Bank Albuquerque NM 35279 First American Bank 25-Jun-10 14-Sep-12
278 First National Bank Savannah GA 34152 The Savannah Bank, N.A. 25-Jun-10 21-Mar-14
279 Peninsula Bank Englewood FL 26563 Premier American Bank, N.A. 25-Jun-10 21-Mar-14
280 Nevada Security Bank Reno NV 57110 Umpqua Bank 18-Jun-10 23-Aug-12
281 Washington First International Bank Seattle WA 32955 East West Bank 11-Jun-10 14-Sep-12
282 TierOne Bank Lincoln NE 29341 Great Western Bank 4-Jun-10 14-Sep-12
283 Arcola Homestead Savings Bank Arcola IL 31813 No Acquirer 4-Jun-10 8-May-15
284 First National Bank Rosedale MS 15814 The Jefferson Bank 4-Jun-10 21-Mar-14
285 Sun West Bank Las Vegas NV 34785 City National Bank 28-May-10 14-Sep-12
286 Granite Community Bank, NA Granite Bay CA 57315 Tri Counties Bank 28-May-10 14-Sep-12
287 Bank of Florida - Tampa Tampa FL 57814 EverBank 28-May-10 8-Aug-16
288 Bank of Florida - Southwest Naples FL 35106 EverBank 28-May-10 8-Aug-16
289 Bank of Florida - Southeast Fort Lauderdale FL 57360 EverBank 28-May-10 8-Aug-16
290 Pinehurst Bank Saint Paul MN 57735 Coulee Bank 21-May-10 26-Oct-12
291 Midwest Bank and Trust Company Elmwood Park IL 18117 FirstMerit Bank, N.A. 14-May-10 23-Aug-12
292 Southwest Community Bank Springfield MO 34255 Simmons First National Bank 14-May-10 4-Feb-16
293 New Liberty Bank Plymouth MI 35586 Bank of Ann Arbor 14-May-10 23-Aug-12
294 Satilla Community Bank Saint Marys GA 35114 Ameris Bank 14-May-10 21-Mar-14
295 1st Pacific Bank of California San Diego CA 35517 City National Bank 7-May-10 13-Dec-12
296 Towne Bank of Arizona Mesa AZ 57697 Commerce Bank of Arizona 7-May-10 23-Aug-12
297 Access Bank Champlin MN 16476 PrinsBank 7-May-10 5-Feb-15
298 The Bank of Bonifay Bonifay FL 14246 First Federal Bank of Florida 7-May-10 5-Nov-12
299 Frontier Bank Everett WA 22710 Union Bank, N.A. 30-Apr-10 15-Jan-13
300 BC National Banks Butler MO 17792 Community First Bank 30-Apr-10 23-Aug-12
301 Champion Bank Creve Coeur MO 58362 BankLiberty 30-Apr-10 6-Jun-16
302 CF Bancorp Port Huron MI 30005 First Michigan Bank 30-Apr-10 13-Apr-16
303 Westernbank Puerto Rico Mayaguez PR 31027 Banco Popular de Puerto Rico 30-Apr-10 21-Mar-14
304 R-G Premier Bank of Puerto Rico Hato Rey PR 32185 Scotiabank de Puerto Rico 30-Apr-10 5-Aug-15
305 Eurobank San Juan PR 27150 Oriental Bank and Trust 30-Apr-10 21-Mar-14
306 Wheatland Bank Naperville IL 58429 Wheaton Bank & Trust 23-Apr-10 23-Aug-12
307 Peotone Bank and Trust Company Peotone IL 10888 First Midwest Bank 23-Apr-10 23-Aug-12
308 Lincoln Park Savings Bank Chicago IL 30600 Northbrook Bank & Trust Company 23-Apr-10 23-Aug-12
309 New Century Bank Chicago IL 34821 MB Financial Bank, N.A. 23-Apr-10 23-Aug-12
310 Citizens Bank and Trust Company of Chicago Chicago IL 34658 Republic Bank of Chicago 23-Apr-10 5-Jun-14
311 Broadway Bank Chicago IL 22853 MB Financial Bank, N.A. 23-Apr-10 23-Aug-12
312 Amcore Bank, National Association Rockford IL 3735 Harris N.A. 23-Apr-10 23-Aug-12
313 City Bank Lynnwood WA 21521 Whidbey Island Bank 16-Apr-10 14-Sep-12
314 Tamalpais Bank San Rafael CA 33493 Union Bank, N.A. 16-Apr-10 23-Aug-12
315 Innovative Bank Oakland CA 23876 Center Bank 16-Apr-10 23-Aug-12
316 Butler Bank Lowell MA 26619 People's United Bank 16-Apr-10 23-Aug-12
317 Riverside National Bank of Florida Fort Pierce FL 24067 TD Bank, N.A. 16-Apr-10 21-Mar-14
318 AmericanFirst Bank Clermont FL 57724 TD Bank, N.A. 16-Apr-10 21-Mar-14
319 First Federal Bank of North Florida Palatka FL 28886 TD Bank, N.A. 16-Apr-10 21-Mar-14
320 Lakeside Community Bank Sterling Heights MI 34878 No Acquirer 16-Apr-10 23-Aug-12
321 Beach First National Bank Myrtle Beach SC 34242 Bank of North Carolina 9-Apr-10 21-Mar-14
322 Desert Hills Bank Phoenix AZ 57060 New York Community Bank 26-Mar-10 23-Aug-12
323 Unity National Bank Cartersville GA 34678 Bank of the Ozarks 26-Mar-10 21-Sep-15
324 Key West Bank Key West FL 34684 Centennial Bank 26-Mar-10 9-Feb-17
325 McIntosh Commercial Bank Carrollton GA 57399 CharterBank 26-Mar-10 11-Jul-16
326 State Bank of Aurora Aurora MN 8221 Northern State Bank 19-Mar-10 8-Aug-16
327 First Lowndes Bank Fort Deposit AL 24957 First Citizens Bank 19-Mar-10 21-Mar-14
328 Bank of Hiawassee Hiawassee GA 10054 Citizens South Bank 19-Mar-10 21-Mar-14
329 Appalachian Community Bank Ellijay GA 33989 Community & Southern Bank 19-Mar-10 21-Mar-14
330 Advanta Bank Corp. Draper UT 33535 No Acquirer 19-Mar-10 31-Mar-16
331 Century Security Bank Duluth GA 58104 Bank of Upson 19-Mar-10 13-Apr-16
332 American National Bank Parma OH 18806 The National Bank and Trust Company 19-Mar-10 21-Sep-15
333 Statewide Bank Covington LA 29561 Home Bank 12-Mar-10 23-Aug-12
334 Old Southern Bank Orlando FL 58182 Centennial Bank 12-Mar-10 9-Feb-17
335 The Park Avenue Bank New York NY 27096 Valley National Bank 12-Mar-10 23-Aug-12
336 LibertyPointe Bank New York NY 58071 Valley National Bank 11-Mar-10 23-Aug-12
337 Centennial Bank Ogden UT 34430 No Acquirer 5-Mar-10 14-Sep-12
338 Waterfield Bank Germantown MD 34976 No Acquirer 5-Mar-10 23-Aug-12
339 Bank of Illinois Normal IL 9268 Heartland Bank and Trust Company 5-Mar-10 23-Aug-12
340 Sun American Bank Boca Raton FL 27126 First-Citizens Bank & Trust Company 5-Mar-10 21-Mar-14
341 Rainier Pacific Bank Tacoma WA 38129 Umpqua Bank 26-Feb-10 23-Aug-12
342 Carson River Community Bank Carson City NV 58352 Heritage Bank of Nevada 26-Feb-10 15-Jan-13
343 La Jolla Bank, FSB La Jolla CA 32423 OneWest Bank, FSB 19-Feb-10 24-Aug-12
344 George Washington Savings Bank Orland Park IL 29952 FirstMerit Bank, N.A. 19-Feb-10 24-Aug-12
345 The La Coste National Bank La Coste TX 3287 Community National Bank 19-Feb-10 19-Aug-14
346 Marco Community Bank Marco Island FL 57586 Mutual of Omaha Bank 19-Feb-10 21-Mar-14
347 1st American State Bank of Minnesota Hancock MN 15448 Community Development Bank, FSB 5-Feb-10 1-Nov-13
348 American Marine Bank Bainbridge Island WA 16730 Columbia State Bank 29-Jan-10 24-Aug-12
349 First Regional Bank Los Angeles CA 23011 First-Citizens Bank & Trust Company 29-Jan-10 4-Mar-16
350 Community Bank and Trust Cornelia GA 5702 SCBT National Association 29-Jan-10 13-Apr-16
351 Marshall Bank, N.A. Hallock MN 16133 United Valley Bank 29-Jan-10 23-Aug-12
352 Florida Community Bank Immokalee FL 5672 Premier American Bank, N.A. 29-Jan-10 21-Mar-14
353 First National Bank of Georgia Carrollton GA 16480 Community & Southern Bank 29-Jan-10 21-Mar-14
354 Columbia River Bank The Dalles OR 22469 Columbia State Bank 22-Jan-10 14-Sep-12
355 Evergreen Bank Seattle WA 20501 Umpqua Bank 22-Jan-10 15-Jan-13
356 Charter Bank Santa Fe NM 32498 Charter Bank 22-Jan-10 23-Aug-12
357 Bank of Leeton Leeton MO 8265 Sunflower Bank, N.A. 22-Jan-10 15-Jan-13
358 Premier American Bank Miami FL 57147 Premier American Bank, N.A. 22-Jan-10 21-Sep-15
359 Barnes Banking Company Kaysville UT 1252 No Acquirer 15-Jan-10 23-Aug-12
360 St. Stephen State Bank St. Stephen MN 17522 First State Bank of St. Joseph 15-Jan-10 8-Aug-16
361 Town Community Bank & Trust Antioch IL 34705 First American Bank 15-Jan-10 23-Aug-12
362 Horizon Bank Bellingham WA 22977 Washington Federal Savings and Loan Association 8-Jan-10 23-Aug-12
363 First Federal Bank of California, F.S.B. Santa Monica CA 28536 OneWest Bank, FSB 18-Dec-09 23-Aug-12
364 Imperial Capital Bank La Jolla CA 26348 City National Bank 18-Dec-09 5-Sep-12
365 Independent Bankers' Bank Springfield IL 26820 The Independent BankersBank (TIB) 18-Dec-09 23-Aug-12
366 New South Federal Savings Bank Irondale AL 32276 Beal Bank 18-Dec-09 23-Aug-12
367 Citizens State Bank New Baltimore MI 1006 No Acquirer 18-Dec-09 21-Mar-14
368 Peoples First Community Bank Panama City FL 32167 Hancock Bank 18-Dec-09 5-Nov-12
369 RockBridge Commercial Bank Atlanta GA 58315 No Acquirer 18-Dec-09 21-Mar-14
370 SolutionsBank Overland Park KS 4731 Arvest Bank 11-Dec-09 19-Jul-16
371 Valley Capital Bank, N.A. Mesa AZ 58399 Enterprise Bank & Trust 11-Dec-09 20-Oct-16
372 Republic Federal Bank, N.A. Miami FL 22846 1st United Bank 11-Dec-09 21-Mar-14
373 Greater Atlantic Bank Reston VA 32583 Sonabank 4-Dec-09 21-Mar-14
374 Benchmark Bank Aurora IL 10440 MB Financial Bank, N.A. 4-Dec-09 23-Aug-12
375 AmTrust Bank Cleveland OH 29776 New York Community Bank 4-Dec-09 21-Mar-14
376 The Tattnall Bank Reidsville GA 12080 Heritage Bank of the South 4-Dec-09 21-Mar-14
377 First Security National Bank Norcross GA 26290 State Bank and Trust Company 4-Dec-09 17-Oct-15
378 The Buckhead Community Bank Atlanta GA 34663 State Bank and Trust Company 4-Dec-09 21-Mar-14
379 Commerce Bank of Southwest Florida Fort Myers FL 58016 Central Bank 20-Nov-09 21-Mar-14
380 Pacific Coast National Bank San Clemente CA 57914 Sunwest Bank 13-Nov-09 10-Apr-17
381 Orion Bank Naples FL 22427 IBERIABANK 13-Nov-09 21-Mar-14
382 Century Bank, F.S.B. Sarasota FL 32267 IBERIABANK 13-Nov-09 21-Mar-14
383 United Commercial Bank San Francisco CA 32469 East West Bank 6-Nov-09 5-Nov-12
384 Gateway Bank of St. Louis St. Louis MO 19450 Central Bank of Kansas City 6-Nov-09 22-Aug-12
385 Prosperan Bank Oakdale MN 35074 Alerus Financial, N.A. 6-Nov-09 22-Aug-12
386 Home Federal Savings Bank Detroit MI 30329 Liberty Bank and Trust Company 6-Nov-09 22-Aug-12
387 United Security Bank Sparta GA 22286 Ameris Bank 6-Nov-09 21-Mar-14
388 North Houston Bank Houston TX 18776 U.S. Bank N.A. 30-Oct-09 22-Aug-12
389 Madisonville State Bank Madisonville TX 33782 U.S. Bank N.A. 30-Oct-09 22-Aug-12
390 Citizens National Bank Teague TX 25222 U.S. Bank N.A. 30-Oct-09 22-Aug-12
391 Park National Bank Chicago IL 11677 U.S. Bank N.A. 30-Oct-09 22-Aug-12
392 Pacific National Bank San Francisco CA 30006 U.S. Bank N.A. 30-Oct-09 22-Aug-12
393 California National Bank Los Angeles CA 34659 U.S. Bank N.A. 30-Oct-09 5-Sep-12
394 San Diego National Bank San Diego CA 23594 U.S. Bank N.A. 30-Oct-09 22-Aug-12
395 Community Bank of Lemont Lemont IL 35291 U.S. Bank N.A. 30-Oct-09 15-Jan-13
396 Bank USA, N.A. Phoenix AZ 32218 U.S. Bank N.A. 30-Oct-09 22-Aug-12
397 First DuPage Bank Westmont IL 35038 First Midwest Bank 23-Oct-09 22-Aug-12
398 Riverview Community Bank Otsego MN 57525 Central Bank 23-Oct-09 22-Aug-12
399 Bank of Elmwood Racine WI 18321 Tri City National Bank 23-Oct-09 22-Aug-12
400 Flagship National Bank Bradenton FL 35044 First Federal Bank of Florida 23-Oct-09 5-Feb-15
401 Hillcrest Bank Florida Naples FL 58336 Stonegate Bank 23-Oct-09 22-Aug-12
402 American United Bank Lawrenceville GA 57794 Ameris Bank 23-Oct-09 5-Sep-12
403 Partners Bank Naples FL 57959 Stonegate Bank 23-Oct-09 5-Feb-15
404 San Joaquin Bank Bakersfield CA 23266 Citizens Business Bank 16-Oct-09 22-Aug-12
405 Southern Colorado National Bank Pueblo CO 57263 Legacy Bank 2-Oct-09 12-Dec-16
406 Jennings State Bank Spring Grove MN 11416 Central Bank 2-Oct-09 21-Aug-12
407 Warren Bank Warren MI 34824 The Huntington National Bank 2-Oct-09 21-Aug-12
408 Georgian Bank Atlanta GA 57151 First Citizens Bank and Trust Company, Inc. 25-Sep-09 21-Aug-12
409 Irwin Union Bank, F.S.B. Louisville KY 57068 First Financial Bank, N.A. 18-Sep-09 5-Sep-12
410 Irwin Union Bank and Trust Company Columbus IN 10100 First Financial Bank, N.A. 18-Sep-09 21-Aug-12
411 Venture Bank Lacey WA 22868 First-Citizens Bank & Trust Company 11-Sep-09 21-Aug-12
412 Brickwell Community Bank Woodbury MN 57736 CorTrust Bank N.A. 11-Sep-09 20-Oct-16
413 Corus Bank, N.A. Chicago IL 13693 MB Financial Bank, N.A. 11-Sep-09 21-Aug-12
414 First State Bank Flagstaff AZ 34875 Sunwest Bank 4-Sep-09 5-Feb-15
415 Platinum Community Bank Rolling Meadows IL 35030 No Acquirer 4-Sep-09 21-Aug-12
416 Vantus Bank Sioux City IA 27732 Great Southern Bank 4-Sep-09 21-Aug-12
417 InBank Oak Forest IL 20203 MB Financial Bank, N.A. 4-Sep-09 17-Oct-15
418 First Bank of Kansas City Kansas City MO 25231 Great American Bank 4-Sep-09 21-Aug-12
419 Affinity Bank Ventura CA 27197 Pacific Western Bank 28-Aug-09 21-Aug-12
420 Mainstreet Bank Forest Lake MN 1909 Central Bank 28-Aug-09 21-Aug-12
421 Bradford Bank Baltimore MD 28312 Manufacturers and Traders Trust Company (M&T Bank) 28-Aug-09 15-Jan-13
422 Guaranty Bank Austin TX 32618 BBVA Compass 21-Aug-09 21-Aug-12
423 CapitalSouth Bank Birmingham AL 22130 IBERIABANK 21-Aug-09 15-Jan-13
424 First Coweta Bank Newnan GA 57702 United Bank 21-Aug-09 7-Dec-15
425 ebank Atlanta GA 34682 Stearns Bank, N.A. 21-Aug-09 21-Aug-12
426 Community Bank of Nevada Las Vegas NV 34043 No Acquirer 14-Aug-09 21-Aug-12
427 Community Bank of Arizona Phoenix AZ 57645 MidFirst Bank 14-Aug-09 21-Aug-12
428 Union Bank, National Association Gilbert AZ 34485 MidFirst Bank 14-Aug-09 21-Aug-12
429 Colonial Bank Montgomery AL 9609 Branch Banking & Trust Company, (BB&T) 14-Aug-09 12-Jun-14
430 Dwelling House Savings and Loan Association Pittsburgh PA 31559 PNC Bank, N.A. 14-Aug-09 15-Jan-13
431 Community First Bank Prineville OR 23268 Home Federal Bank 7-Aug-09 15-Jan-13
432 Community National Bank of Sarasota County Venice FL 27183 Stearns Bank, N.A. 7-Aug-09 20-Aug-12
433 First State Bank Sarasota FL 27364 Stearns Bank, N.A. 7-Aug-09 20-Aug-12
434 Mutual Bank Harvey IL 18659 United Central Bank 31-Jul-09 20-Aug-12
435 First BankAmericano Elizabeth NJ 34270 Crown Bank 31-Jul-09 20-Aug-12
436 Peoples Community Bank West Chester OH 32288 First Financial Bank, N.A. 31-Jul-09 20-Aug-12
437 Integrity Bank Jupiter FL 57604 Stonegate Bank 31-Jul-09 20-Aug-12
438 First State Bank of Altus Altus OK 9873 Herring Bank 31-Jul-09 20-Aug-12
439 Security Bank of Jones County Gray GA 8486 State Bank and Trust Company 24-Jul-09 20-Aug-12
440 Security Bank of Houston County Perry GA 27048 State Bank and Trust Company 24-Jul-09 17-Oct-15
441 Security Bank of Bibb County Macon GA 27367 State Bank and Trust Company 24-Jul-09 20-Aug-12
442 Security Bank of North Metro Woodstock GA 57105 State Bank and Trust Company 24-Jul-09 6-Jan-16
443 Security Bank of North Fulton Alpharetta GA 57430 State Bank and Trust Company 24-Jul-09 20-Aug-12
444 Security Bank of Gwinnett County Suwanee GA 57346 State Bank and Trust Company 24-Jul-09 20-Aug-12
445 Waterford Village Bank Williamsville NY 58065 Evans Bank, N.A. 24-Jul-09 1-Nov-13
446 Temecula Valley Bank Temecula CA 34341 First-Citizens Bank & Trust Company 17-Jul-09 20-Oct-16
447 Vineyard Bank Rancho Cucamonga CA 23556 California Bank & Trust 17-Jul-09 20-Aug-12
448 BankFirst Sioux Falls SD 34103 Alerus Financial, N.A. 17-Jul-09 20-Aug-12
449 First Piedmont Bank Winder GA 34594 First American Bank and Trust Company 17-Jul-09 8-Aug-16
450 Bank of Wyoming Thermopolis WY 22754 Central Bank & Trust 10-Jul-09 20-Aug-12
451 Founders Bank Worth IL 18390 The PrivateBank and Trust Company 2-Jul-09 20-Aug-12
452 Millennium State Bank of Texas Dallas TX 57667 State Bank of Texas 2-Jul-09 26-Oct-12
453 First National Bank of Danville Danville IL 3644 First Financial Bank, N.A. 2-Jul-09 20-Aug-12
454 Elizabeth State Bank Elizabeth IL 9262 Galena State Bank and Trust Company 2-Jul-09 20-Aug-12
455 Rock River Bank Oregon IL 15302 The Harvard State Bank 2-Jul-09 20-Aug-12
456 First State Bank of Winchester Winchester IL 11710 The First National Bank of Beardstown 2-Jul-09 20-Aug-12
457 John Warner Bank Clinton IL 12093 State Bank of Lincoln 2-Jul-09 20-Aug-12
458 Mirae Bank Los Angeles CA 57332 Wilshire State Bank 26-Jun-09 20-Aug-12
459 MetroPacific Bank Irvine CA 57893 Sunwest Bank 26-Jun-09 5-Feb-15
460 Horizon Bank Pine City MN 9744 Stearns Bank, N.A. 26-Jun-09 5-Feb-15
461 Neighborhood Community Bank Newnan GA 35285 CharterBank 26-Jun-09 7-Dec-15
462 Community Bank of West Georgia Villa Rica GA 57436 No Acquirer 26-Jun-09 17-Aug-12
463 First National Bank of Anthony Anthony KS 4614 Bank of Kansas 19-Jun-09 21-Sep-15
464 Cooperative Bank Wilmington NC 27837 First Bank 19-Jun-09 17-Aug-12
465 Southern Community Bank Fayetteville GA 35251 United Community Bank 19-Jun-09 21-Sep-15
466 Bank of Lincolnwood Lincolnwood IL 17309 Republic Bank of Chicago 5-Jun-09 17-Aug-12
467 Citizens National Bank Macomb IL 5757 Morton Community Bank 22-May-09 4-Sep-12
468 Strategic Capital Bank Champaign IL 35175 Midland States Bank 22-May-09 4-Sep-12
469 BankUnited, FSB Coral Gables FL 32247 BankUnited 21-May-09 17-Aug-12
470 Westsound Bank Bremerton WA 34843 Kitsap Bank 8-May-09 4-Sep-12
471 America West Bank Layton UT 35461 Cache Valley Bank 1-May-09 17-Aug-12
472 Citizens Community Bank Ridgewood NJ 57563 North Jersey Community Bank 1-May-09 4-Sep-12
473 Silverton Bank, NA Atlanta GA 26535 No Acquirer 1-May-09 17-Aug-12
474 First Bank of Idaho Ketchum ID 34396 U.S. Bank, N.A. 24-Apr-09 17-Aug-12
475 First Bank of Beverly Hills Calabasas CA 32069 No Acquirer 24-Apr-09 4-Sep-12
476 Michigan Heritage Bank Farmington Hills MI 34369 Level One Bank 24-Apr-09 17-Aug-12
477 American Southern Bank Kennesaw GA 57943 Bank of North Georgia 24-Apr-09 17-Aug-12
478 Great Basin Bank of Nevada Elko NV 33824 Nevada State Bank 17-Apr-09 4-Sep-12
479 American Sterling Bank Sugar Creek MO 8266 Metcalf Bank 17-Apr-09 31-Aug-12
480 New Frontier Bank Greeley CO 34881 No Acquirer 10-Apr-09 4-Sep-12
481 Cape Fear Bank Wilmington NC 34639 First Federal Savings and Loan Association 10-Apr-09 10-Apr-17
482 Omni National Bank Atlanta GA 22238 No Acquirer 27-Mar-09 17-Aug-12
483 TeamBank, NA Paola KS 4754 Great Southern Bank 20-Mar-09 12-Sep-16
484 Colorado National Bank Colorado Springs CO 18896 Herring Bank 20-Mar-09 12-Dec-16
485 FirstCity Bank Stockbridge GA 18243 No Acquirer 20-Mar-09 17-Aug-12
486 Freedom Bank of Georgia Commerce GA 57558 Northeast Georgia Bank 6-Mar-09 17-Aug-12
487 Security Savings Bank Henderson NV 34820 Bank of Nevada 27-Feb-09 7-Sep-12
488 Heritage Community Bank Glenwood IL 20078 MB Financial Bank, N.A. 27-Feb-09 17-Aug-12
489 Silver Falls Bank Silverton OR 35399 Citizens Bank 20-Feb-09 17-Aug-12
490 Pinnacle Bank of Oregon Beaverton OR 57342 Washington Trust Bank of Spokane 13-Feb-09 7-Dec-15
491 Corn Belt Bank & Trust Co. Pittsfield IL 16500 The Carlinville National Bank 13-Feb-09 17-Aug-12
492 Riverside Bank of the Gulf Coast Cape Coral FL 34563 TIB Bank 13-Feb-09 17-Aug-12
493 Sherman County Bank Loup City NE 5431 Heritage Bank 13-Feb-09 17-Aug-12
494 County Bank Merced CA 22574 Westamerica Bank 6-Feb-09 4-Sep-12
495 Alliance Bank Culver City CA 23124 California Bank & Trust 6-Feb-09 16-Aug-12
496 FirstBank Financial Services McDonough GA 57017 Regions Bank 6-Feb-09 16-Aug-12
497 Ocala National Bank Ocala FL 26538 CenterState Bank of Florida, N.A. 30-Jan-09 4-Sep-12
498 Suburban FSB Crofton MD 30763 Bank of Essex 30-Jan-09 4-Feb-16
499 MagnetBank Salt Lake City UT 58001 No Acquirer 30-Jan-09 16-Aug-12
500 1st Centennial Bank Redlands CA 33025 First California Bank 23-Jan-09 13-Apr-16
501 Bank of Clark County Vancouver WA 34959 Umpqua Bank 16-Jan-09 16-Aug-12
502 National Bank of Commerce Berkeley IL 19733 Republic Bank of Chicago 16-Jan-09 16-Aug-12
503 Sanderson State Bank Sanderson TX 11568 The Pecos County State Bank 12-Dec-08 25-Oct-13
504 Haven Trust Bank Duluth GA 35379 Branch Banking & Trust Company, (BB&T) 12-Dec-08 16-Aug-12
505 First Georgia Community Bank Jackson GA 34301 United Bank 5-Dec-08 16-Aug-12
506 PFF Bank & Trust Pomona CA 28344 U.S. Bank, N.A. 21-Nov-08 4-Jan-13
507 Downey Savings & Loan Newport Beach CA 30968 U.S. Bank, N.A. 21-Nov-08 4-Jan-13
508 Community Bank Loganville GA 16490 Bank of Essex 21-Nov-08 4-Sep-12
509 Security Pacific Bank Los Angeles CA 23595 Pacific Western Bank 7-Nov-08 28-Aug-12
510 Franklin Bank, SSB Houston TX 26870 Prosperity Bank 7-Nov-08 16-Aug-12
511 Freedom Bank Bradenton FL 57930 Fifth Third Bank 31-Oct-08 16-Aug-12
512 Alpha Bank & Trust Alpharetta GA 58241 Stearns Bank, N.A. 24-Oct-08 16-Aug-12
513 Meridian Bank Eldred IL 13789 National Bank 10-Oct-08 31-May-12
514 Main Street Bank Northville MI 57654 Monroe Bank & Trust 10-Oct-08 1-Aug-13
515 Washington Mutual Bank (Including its subsidiary Washington Mutual Bank FSB) Henderson NV 32633 JP Morgan Chase Bank 25-Sep-08 4-Aug-15
516 Ameribank Northfork WV 6782 The Citizens Savings Bank, Pioneer Community Bank, Inc. 19-Sep-08 21-Sep-15
517 Silver State Bank Henderson NV 34194 Nevada State Bank 5-Sep-08 25-Oct-13
518 Integrity Bank Alpharetta GA 35469 Regions Bank 29-Aug-08 16-Aug-12
519 Columbian Bank & Trust Topeka KS 22728 Citizens Bank & Trust 22-Aug-08 26-Mar-15
520 First Priority Bank Bradenton FL 57523 SunTrust Bank 1-Aug-08 12-Dec-16
521 First Heritage Bank, NA Newport Beach CA 57961 Mutual of Omaha Bank 25-Jul-08 12-Sep-16
522 First National Bank of Nevada Reno NV 27011 Mutual of Omaha Bank 25-Jul-08 28-Aug-12
523 IndyMac Bank Pasadena CA 29730 OneWest Bank, FSB 11-Jul-08 22-Apr-15
524 First Integrity Bank, NA Staples MN 12736 First International Bank and Trust 30-May-08 20-Oct-16
525 ANB Financial, NA Bentonville AR 33901 Pulaski Bank and Trust Company 9-May-08 28-Aug-12
526 Hume Bank Hume MO 1971 Security Bank 7-Mar-08 28-Aug-12
527 Douglass National Bank Kansas City MO 24660 Liberty Bank and Trust Company 25-Jan-08 26-Oct-12
528 Miami Valley Bank Lakeview OH 16848 The Citizens Banking Company 4-Oct-07 12-Sep-16
529 NetBank Alpharetta GA 32575 ING DIRECT 28-Sep-07 28-Aug-12
530 Metropolitan Savings Bank Pittsburgh PA 35353 Allegheny Valley Bank of Pittsburgh 2-Feb-07 27-Oct-10
531 Bank of Ephraim Ephraim UT 1249 Far West Bank 25-Jun-04 9-Apr-08
532 Reliance Bank White Plains NY 26778 Union State Bank 19-Mar-04 9-Apr-08
533 Guaranty National Bank of Tallahassee Tallahassee FL 26838 Hancock Bank of Florida 12-Mar-04 5-Jun-12
534 Dollar Savings Bank Newark NJ 31330 No Acquirer 14-Feb-04 9-Apr-08
535 Pulaski Savings Bank Philadelphia PA 27203 Earthstar Bank 14-Nov-03 22-Jul-05
536 First National Bank of Blanchardville Blanchardville WI 11639 The Park Bank 9-May-03 5-Jun-12
537 Southern Pacific Bank Torrance CA 27094 Beal Bank 7-Feb-03 20-Oct-08
538 Farmers Bank of Cheneyville Cheneyville LA 16445 Sabine State Bank & Trust 17-Dec-02 20-Oct-04
539 Bank of Alamo Alamo TN 9961 No Acquirer 8-Nov-02 18-Mar-05
540 AmTrade International Bank Atlanta GA 33784 No Acquirer 30-Sep-02 11-Sep-06
541 Connecticut Bank of Commerce Stamford CT 19183 Hudson United Bank 26-Jun-02 14-Feb-12
542 New Century Bank Shelby Township MI 34979 No Acquirer 28-Mar-02 18-Mar-05
543 Net 1st National Bank Boca Raton FL 26652 Bank Leumi USA 1-Mar-02 9-Apr-08
544 NextBank, NA Phoenix AZ 22314 No Acquirer 7-Feb-02 5-Feb-15
545 Oakwood Deposit Bank Co. Oakwood OH 8966 The State Bank & Trust Company 1-Feb-02 25-Oct-12
546 Bank of Sierra Blanca Sierra Blanca TX 22002 The Security State Bank of Pecos 18-Jan-02 6-Nov-03
547 Hamilton Bank, NA Miami FL 24382 Israel Discount Bank of New York 11-Jan-02 21-Sep-15
548 Superior Bank, FSB Hinsdale IL 32646 Superior Federal, FSB 27-Jul-01 19-Aug-14
549 Malta National Bank Malta OH 6629 North Valley Bank 3-May-01 18-Nov-02
550 First Alliance Bank & Trust Co. Manchester NH 34264 Southern New Hampshire Bank & Trust 2-Feb-01 18-Feb-03
551 National State Bank of Metropolis Metropolis IL 3815 Banterra Bank of Marion 14-Dec-00 17-Mar-05
552 Bank of Honolulu Honolulu HI 21029 Bank of the Orient 13-Oct-00 17-Mar-05

5
03-Pandas/example Normal file
View File

@ -0,0 +1,5 @@
a,b,c,d
0,1,2,3
4,5,6,7
8,9,10,11
12,13,14,15

5
03-Pandas/example.csv Normal file
View File

@ -0,0 +1,5 @@
a,b,c,d
0,1,2,3
4,5,6,7
8,9,10,11
12,13,14,15
1 a b c d
2 0 1 2 3
3 4 5 6 7
4 8 9 10 11
5 12 13 14 15

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

View File

@ -0,0 +1,6 @@
{
"cells": [],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 2
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,11 @@
a,b,c,d
0.039761986133905136,0.2185172274750622,0.10342298051665423,0.9579042338107532
0.9372879037285884,0.04156728027953449,0.8991254222382951,0.9776795571253272
0.7805044779316328,0.008947537857148302,0.5578084027546968,0.7975104497549266
0.6727174963492204,0.24786984946279625,0.2640713103088026,0.44435791644122935
0.05382860859967886,0.5201244020579979,0.5522642392797277,0.19000759632053632
0.2860433671280178,0.5934650440000543,0.9073072637456548,0.6378977150631427
0.4304355863327313,0.16623013749421356,0.4693825447762464,0.4977008828313123
0.3122955538295512,0.5028232900921878,0.8066087010958843,0.8505190941429479
0.1877648514121828,0.9970746427719338,0.8959552961495315,0.530390137569463
0.9081621790575398,0.23272641071536715,0.4141382611943452,0.4320069001558664

View File

@ -0,0 +1,501 @@
a,b,c,d
0.33627233637218457,0.3250110687231613,0.0010196408377848298,0.40140189720154196
0.9802649683525543,0.8318353550307083,0.7722883679048234,0.0764853766737329
0.4803872425787493,0.6868393727588189,0.0005746529724915961,0.7467584765703297
0.5021060966555528,0.305141589099338,0.7686084672112038,0.6546851999553737
0.856602037495124,0.17144842884142553,0.1579712921580272,0.321231483243839
0.705973481075289,0.6326888750520957,0.5040165014387529,0.313622137930175
0.16672441593320897,0.26973375516469766,0.6085693621704945,0.8744271309803985
0.054040593105187384,0.9664396927503365,0.06559570391295622,0.10944814243870982
0.7578390928377232,0.5238852910755655,0.5272102788067565,0.22693647922759852
0.4253833221643635,0.21370125617072533,0.04902015655465275,0.2875979408000324
0.17683680950823633,0.16653356599751545,0.7793735548048444,0.9364861878339583
0.22154585464980914,0.6608213750146527,0.8117815897698992,0.39256501309009495
0.0013503699623585996,0.45018589348741,0.07646946429641399,0.7533679412337956
0.5373231464576197,0.6237788989227707,0.07185135746180549,0.7512000510131361
0.03228400416591837,0.050181912070182855,0.8975624866722012,0.6141292789106866
0.48880423301062903,0.091374385826271,0.20380306481467603,0.17970794983894278
0.8211155924257206,0.19140670507340207,0.7569623666417657,0.5923832772664127
0.202698689394757,0.10397814468661737,0.3422364309240138,0.7876262313490752
0.18521752139529557,0.7515544279051898,0.6127372143065575,0.08842911001592957
0.8428103260014432,0.8423568831968558,0.20658856394692127,0.3899396257210873
0.8440331226076548,0.4499813871558678,0.13219758424637973,0.10393829250389419
0.16387799113366353,0.11235392778846287,0.2190873453625617,0.059326947648009165
0.33190219209756044,0.8080268099068179,0.5101723811744628,0.3875393176456404
0.5016420034152848,0.9413004247947276,0.3237529405161287,0.6909106696226429
0.37151955223345456,0.8763309746266572,0.14435751886650183,0.594585432452638
0.994328979706033,0.4147718333263406,0.4402798249423783,0.547651126220843
0.00679971308197036,0.4603723951885834,0.09186946680903141,0.5517256896624096
0.2038574471303466,0.30806922777314416,0.24075597273301397,0.9809566340486252
0.6057790651048847,0.380763712827924,0.7929227833553262,0.8916493533755211
0.4773044457751652,0.18348921227398018,0.8665347875764602,0.20115355252830047
0.5562623859121136,0.12741251095832018,0.5668972900386939,0.37582831435355124
0.6094551685345265,0.4238303848935505,0.06312888353038026,0.9296411624795633
0.2830144384308311,0.34994725136301763,0.7866534502340554,0.5685738387259147
0.6083096069069768,0.8547908027081947,0.1394453009020623,0.4875846563151508
0.7950019425815656,0.921310174399855,0.7131410421635475,0.6854997471830577
0.7029167242052079,0.9942208895868356,0.1578293248971958,0.7526027061070005
0.009322285637569871,0.8523851062431688,0.9869823482550834,0.34136544005312386
0.12852080402532928,0.596241240318469,0.3968413103480981,0.7848552860308265
0.002236448759129761,0.5637356470041152,0.8886645729272742,0.37386485230236577
0.7842827419476831,0.4992192667366049,0.45170232654581244,0.3770787550311161
0.9158907842654865,0.6409957558601469,0.49568773910025465,0.20171709368134993
0.19497218789426773,0.07799977284048609,0.45164626525047646,0.41569643117464683
0.18132400560860884,0.5661707175707383,0.6056319811909233,0.4165675770381041
0.38488773142764265,0.9821137122971909,0.5027171764378315,0.813578153903196
0.293214680847236,0.13178425655004344,0.653358739460729,0.9163419033861513
0.24049964437381832,0.25836815014457226,0.8576721350402634,0.6353489072771664
0.7845072207604514,0.5549383922577203,0.9430359879805484,0.020917179653205498
0.4890808014256227,0.6437666545983554,0.04664450518739238,0.9578885394454532
0.4228457628977761,0.8689120616410727,0.7972507965819937,0.019856966453678848
0.9241867489910823,0.41850080577561566,0.4394385762716323,0.8024008068527704
0.8305625919210394,0.3108978272568762,0.6129356703058603,0.8716646405910411
0.09594336918253688,0.019040152853489145,0.8979912879493811,0.84308872060182
0.009327986936045307,0.8866217728884342,0.4970262702960242,0.5585917930674684
0.7659452276041034,0.021081125490953756,0.05379451175469152,0.13182088392280134
0.5137324258205391,0.03507429771742998,0.6188835497462247,0.47412112348613267
0.11358486552277647,0.5406403944158276,0.0729449248495877,0.5527552831548942
0.08956748867615882,0.11654922503912224,0.46266652129506614,0.32642602885962135
0.4211171586740562,0.6632165454855101,0.6309662913224898,0.8286446436953286
0.5637355341677186,0.9629205938326909,0.48836102148628124,0.179301852727608
0.5665145754302383,0.47465892280959876,0.7069399194676959,0.6843231102049017
0.7919669843727317,0.41286717347824753,0.2199075673075842,0.7190515874041887
0.4540253976165326,0.8591098044317296,0.05641593355299912,0.052499941434040465
0.8676454047696701,0.8060309968112127,0.7976554814027406,0.3095319522235279
0.4034305635707125,0.03613418459915807,0.3325763107210705,0.9512794915551748
0.20653241823964685,0.6811942258264632,0.1388068478997746,0.907449529319709
0.9099121743964399,0.6749347933657847,0.7193643552406551,0.5879654995595851
0.9521397233570815,0.3402404046288864,0.7324666461948954,0.8387632211906879
0.8421351523246728,0.961220138564085,0.4778471184712483,0.5306040734200057
0.7258327483128492,0.12740590844845978,0.5227115974518366,0.9165137051199156
0.39726230939877916,0.9205270920019915,0.37890315076336945,0.8293212927684726
0.5096842992720936,0.34492156831348975,0.21972392428167264,0.3239206526071199
0.41923610692712787,0.20316889038447328,0.6723821379431006,0.8138336994323886
0.5401022043036029,0.9921912472869507,0.07155264815748197,0.22235205692332194
0.6326231970067655,0.6711395741968569,0.5362098362111336,0.1269112826214921
0.0767867395670696,0.3565016862470717,0.25388441759642566,0.4242950025417688
0.4874105739319312,0.25271393595678326,0.7120803949787771,0.6989636412956753
0.865351123549325,0.47276683251320106,0.349365609886252,0.970488584408135
0.17522331971527527,0.858030698062132,0.014161641133221714,0.9590157903088603
0.5219950450807564,0.564292482855931,0.991807593090961,0.8793987668720515
0.8541851689759502,0.4312804455508483,0.9057447902854223,0.8400308135512039
0.24962152163352236,0.29976093447523944,0.016659801635567795,0.6113981828515243
0.5256246254031416,0.7025797018077921,0.45370147271924066,0.21847018115707095
0.7773168862825681,0.5807690145037084,0.05917681562835819,0.12207149221630365
0.2969398693899853,0.7101837014089161,0.10264566154018484,0.03802663652391913
0.13174726635317047,0.4049640420658098,0.10265639488345568,0.6313356859556932
0.5774537613732307,0.7950091343310087,0.6254072054481303,0.782880581402316
0.4569088828401272,0.3368057405210615,0.7644526823895249,0.7169545580826315
0.04405209275176336,0.2643936018285221,0.9125333461775873,0.14914103967117964
0.9507443774090862,0.027600609976992874,0.8764198054026865,0.879444004820502
0.5842083305136452,0.6274659945637009,0.5367451676231368,0.392889215931417
0.8955122098248628,0.7537782106513566,0.1604911709350293,0.5859829839384009
0.5952961818963642,0.7468739882549703,0.24275681153732187,0.5290670495598715
0.8312535242920208,0.1917211521709924,0.9220747852006578,0.1970401675822976
0.46147635658104025,0.2036694441526835,0.9732520838928433,0.09224453800897414
0.09164896639336784,0.5623431916696897,0.03226422662199835,0.09150761256404727
0.0027739897107698086,0.4861197117786701,0.2969232876902048,0.14349432537135687
0.5654476076298837,0.02937985987233005,0.9763755947396335,0.8867719187512502
0.2970657038748554,0.6517747699408414,0.8441592978236552,0.9189007059914814
0.18759092285878176,0.5612541486109694,0.24432183733750223,0.8822158061277604
0.48605710009116976,0.2611925264780821,0.6175926575199631,0.8091933051351528
0.06034437375304058,0.5013711741578023,0.8991711485489406,0.2201862984008226
0.25535590055309276,0.3516679243024956,0.5364893477060845,0.03701102753929619
0.31328688355417955,0.4763862834554521,0.9202864658634526,0.7631840375981793
0.10431853303024763,0.2851353342832237,0.41775437331758203,0.516107005989879
0.42920953935242556,0.6462710684488812,0.5332567085391797,0.28323321173177096
0.6125472392222696,0.9333035762795235,0.3152303713785083,0.5077422637945377
0.4626467454001375,0.7057207724407146,0.947799261099005,0.41181935062478436
0.7069326445918329,0.6083604272727989,0.6411963088604483,0.8910570722746401
0.35738719547306785,0.1749638427392035,0.7126113738291732,0.3418569615350563
0.8996328040943408,0.07215553808738318,0.950727768044252,0.014300048486940553
0.04724141430866824,0.244668538365997,0.07762066561538628,0.7853375044908923
0.16085880428253185,0.5143846890922119,0.12297488332527828,0.8819848358310923
0.42142592069833285,0.12287317618823113,0.30114178431109306,0.7939797237336467
0.8815288737565792,0.39151559779951806,0.6958394710958453,0.7814010010773164
0.44394332894315436,0.07553068723802092,0.37275528784516443,0.7615758767045683
0.374409464028312,0.5818786972823738,0.08377247884294892,0.3683448657746946
0.9899294933222142,0.1187671466861393,0.4014778191591516,0.5685096489097043
0.06915770697644774,0.6090114308381936,0.6220271462009369,0.559585715262603
0.15955405478675377,0.7359109918618787,0.5084386068305188,0.7045890693080764
0.23296787478109893,0.03259270193505115,0.33995869443762594,0.056452241818247595
0.9886431070907975,0.7427660704163951,0.031265351045515644,0.7292813741972919
0.25761140232278557,0.9690281519031503,0.2205030584495753,0.1340893432229462
0.48712877508762054,0.4065577726204984,0.5439985356525793,0.6179781655968418
0.02453108907718138,0.7449006851219485,0.016648998371553758,0.7632656212788141
0.03249802874858365,0.029654017485838513,0.14598435219688843,0.6408019322014568
0.3532835865948927,0.4939428604587679,0.3473581714765762,0.9615931874740967
0.2918184026405345,0.8537398124259274,0.6155473635818071,0.3552247355799426
0.12703792681969273,0.12599178150105628,0.4336252645614862,0.3654410053985607
0.6810643435533861,0.3148121150987331,0.399335464667698,0.030530634936642875
0.9528797882146893,0.12908033520074214,0.8098651406333642,0.7013259143682808
0.23536709423598234,0.37478763941226545,0.19842775634944565,0.7562456005854551
0.4318457382401344,0.9967400188922231,0.6626892965429728,0.5111869508038237
0.634722769256735,0.33641812662999937,0.20032521735368292,0.5413886778285673
0.30105662499849395,0.8239463258938328,0.7637786846988948,0.6552935262376625
0.4441603799049635,0.3377263099523602,0.8155043986264426,0.06848219164654568
0.04548148661580664,0.2709726235565958,0.12465858380131734,0.6591615115575256
0.03471336985920148,0.7122901580430191,0.9701661055346469,0.6643970613424024
0.9520651381177343,0.3756720203771867,0.3496562090980858,0.32632321104344
0.8442220000866414,0.5107899461278133,0.902689007858361,0.5426324179894695
0.34697608473928676,0.29136838696844236,0.4082087104041593,0.512158775785004
0.28822069677111695,0.2140493866097244,0.8101917324399203,0.5005469421934069
0.8098131526492203,0.60964587312313,0.21065530014928446,0.8726083090048955
0.21337066838328622,0.9415404807508847,0.8702682174016022,0.6119646007822085
0.16678272406244066,0.5636359806161614,0.6838634496961317,0.17855139525600738
0.9606328566850059,0.10116986534500116,0.7352811690185582,0.7111515299969101
0.6948295769243019,0.5487648112166836,0.5971291356412485,0.5862243401316085
0.25466959663484046,0.03759741654816673,0.18492537417920019,0.3152077908652684
0.3538690888280669,0.6923581246513688,0.3413271435268187,0.028229200117313447
0.6643494763809131,0.46728315384847796,0.8177161446969633,0.6303374347843743
0.7550330801551735,0.5106606444950341,0.21877641466826825,0.22235314483650004
0.15145309679350605,0.0401938695342976,0.7530073889402137,0.3690417275588833
0.9760685110956365,0.2832833013287801,0.4101558258510867,0.8616901800434409
0.02985473595547594,0.7877747487646194,0.23130056297184654,0.9396871681614409
0.43602827118441545,0.49652538353669173,0.8350577337150469,0.7952136319405787
0.3093890857172835,0.46716935030046847,0.871500307938109,0.8657480183233166
0.2456914356877259,0.3990168265017442,0.30165988670453503,0.5018761389125409
0.773366902423847,0.7898400491523931,0.05466436722123824,0.6342304807902118
0.4355946549280614,0.21559267306867713,0.6945566395803673,0.06647684585216618
0.9531814883655881,0.5729141047206507,0.3284221987073983,0.019349445686161593
0.8554531512435155,0.4048714779813064,0.8191084513172708,0.8869425223890415
0.22378459698214903,0.6316513388678091,0.59867596778096,0.5453828996141791
0.7521968015369107,0.9383241204971419,0.26832367689036263,0.9236933301521059
0.2538420334987834,0.35565504542848503,0.9918313814463339,0.40459295128860495
0.8512943399155619,0.8145754646436317,0.2300391756142256,0.7616764915071941
0.9089776204805422,0.06301564577463226,0.6886391518337929,0.143418841185596
0.6668972843336031,0.9906466338305843,0.8830389070595589,0.12366815086187177
0.41012099619110054,0.7086901572451703,0.21852541360024869,0.3997955763014477
0.7880107069926059,0.7394352290465452,0.9389903778450293,0.7113562153904642
0.16317523834417125,0.7741475223419458,0.5724701320943584,0.859481296551717
0.5457473442888628,0.3729328111922159,0.51884039225534,0.7386824796906086
0.6908968027745845,0.08280627925444328,0.06723392896082436,0.24671328573661044
0.8520623845068883,0.5969710472617193,0.7697327278098809,0.19740658652708765
0.2574451556296956,0.6621468830829318,0.8412805097791126,0.8651817484405847
0.01981522137598979,0.24439952915330643,0.28254858839247365,0.04322511390909678
0.519024275152464,0.9831608667734769,0.7771341747545258,0.6718284665140184
0.00041033035366877524,0.12073612441607873,0.9580945140036871,0.49285436029614804
0.765613057681015,0.9840407827973151,0.4242176295457398,0.5253199938914017
0.20341140639091282,0.5991055566146712,0.7023042489065016,0.4747723187558055
0.7400900050414457,0.17271094754083793,0.4240999290757701,0.9793393433428702
0.25820029030355063,0.2728668186538884,0.6322054634098652,0.15238618337531795
0.5328537481137854,0.5311755568123224,0.7124676069252257,0.7543900408669565
0.40499751324417577,0.07053712315111249,0.5414349568194385,0.8602525352837128
0.7167405690532722,0.7655360893975195,0.5152671741703145,0.9190770436346825
0.88961057246162,0.6254855074738592,0.29409673513750034,0.7109777546908304
0.4293142758847388,0.07500440719979173,0.8765165097980312,0.21529622822921213
0.2589801994183899,0.06160881811943064,0.3056520716803025,0.982334083651339
0.7902310273315167,0.7894298793784357,0.48208921502203306,0.6202306441826341
0.22466284393364877,0.12148597193505006,0.46103311942117764,0.3483662428684401
0.57742763442928,0.11828978574400584,0.4131676012891534,0.609522879857421
0.37324999603891995,0.6762975414394721,0.9199544769836527,0.6727504995045568
0.711766017902915,0.7939550457590105,0.898307777950035,0.3031826214956438
0.5369879704146969,0.0672550683511125,0.521581223662644,0.8497801425248154
0.47219976377187045,0.18238353765328474,0.64134961311078,0.6349174852105679
0.14624800172865604,0.27381356996678785,0.8224393469115399,0.26937877539963895
0.6794486644723616,0.777012108386266,0.818370703325512,0.3194693652715377
0.26256894387243823,0.8155410401668229,0.7696362130828602,0.3430597160802066
0.9534675119281499,0.4104432184290736,0.8006056593860142,0.005469418655068337
0.22697530159965018,0.3562781425906293,0.42398767253513214,0.5660547467854499
0.46596218753247365,0.6166765020752157,0.6519869790728867,0.85236029707832
0.22480145227830328,0.8716277153913593,0.9538694917004743,0.036617369018068446
0.08734034737180296,0.6818598657649276,0.7118099804139644,0.027208495222140416
0.22675117581361248,0.5093225169066515,0.2527763043257748,0.9639863410064701
0.8588116851970607,0.010648950953201508,0.8614073660606832,0.6625653273689048
0.4032633523884259,0.7190336009781118,0.46849644053207895,0.6931989847582659
0.6483604621209498,0.5821755673849227,0.1163795863804884,0.8319955295555067
0.33164962908476237,0.7666367603030417,0.45294386557535204,0.9719452072879635
0.24813923094249446,0.16216162422596236,0.920552793506166,0.07422765299018297
0.7748669260198029,0.5082087357106482,0.3810680042430784,0.006379281376213353
0.0049458797302726065,0.5287299040999536,0.2220534845790877,0.35056975084558806
0.591143058163664,0.8281272713471354,0.10557105079938112,0.3960752060779493
0.46918815061405417,0.5598337169460946,0.6153953549781171,0.32641048588855914
0.5267835440102993,0.8921297487342501,0.7969345924884385,0.607928404254362
0.6575218281892343,0.6133344689697782,0.026674317422172078,0.6794473556002295
0.8668190580498522,0.46775642509925586,0.7806493405916398,0.8496739290235378
0.1244648752899119,0.36771182500646804,0.747766813278335,0.005027986269138474
0.326904788429768,0.8301066768156419,0.5583885615475986,0.35043091639101154
0.21878840733396754,0.30890306323298644,0.26063368013827903,0.19940888399650192
0.47725115799390283,0.4519491379395325,0.9390538584039441,0.28414276135065464
0.08375430918146376,0.7513028963268265,0.10330365544229436,0.8140028380808133
0.7518322565413479,0.35891329691832896,0.626080838727002,0.5718455198448357
0.8393551543401457,0.9798296662023601,0.1619441133529892,0.9050804752896568
0.2912547699822662,0.8102055466256184,0.029132319044678723,0.3158557431833995
0.9148656321018671,0.8358907745950482,0.13959370006216,0.11068322090759253
0.6462408716160324,0.2066776752496059,0.7556240037237695,0.08049990019889608
0.3229890299355197,0.4421092716998414,0.9774141928524789,0.4826916383029839
0.19899537213792595,0.6483881552956826,0.9603949241226026,0.7460398701642762
0.5929616245255648,0.5036138878742359,0.18643020378853825,0.3734615212449818
0.8606455272824358,0.9449017405763951,0.14989514119892955,0.40871761666733475
0.09117712354115515,0.6484436120663334,0.7448051068584821,0.4718552300107698
0.6481453770004487,0.10128509718921264,0.11964736864520609,0.8938592498582604
0.8586645297808357,0.43434004725542574,0.19382024972204337,0.4701398582696664
0.5752608568445848,0.5289492967771696,0.17095235409262333,0.808798455412136
0.04099322454733356,0.7027125073321747,0.3247808840325497,0.46652225478299536
0.8545900646258339,0.9000924844460604,0.6711822725580922,0.46373836343886
0.9784349555067512,0.47815086615571867,0.31653408382502835,0.8409104059461735
0.08965086313576731,0.35615798789552344,0.679037507855203,0.576862661578551
0.822147160688062,0.22044591928818968,0.622025707499033,0.6356217585107622
0.9659284010312518,0.7137133305963123,0.42468924235462546,0.8825389487233778
0.2652004177722498,0.5565624836551789,0.7138942985137977,0.04313867103058555
0.7204906388512048,0.19300261774017968,0.5553078337805508,0.848623095012623
0.3137020128453659,0.06213788668138398,0.1104521743306962,0.268482638609996
0.3339131616047203,0.22286051556127495,0.9302085063006681,0.18969921720557925
0.47371881012743333,0.27649916957853926,0.918582911002254,0.9077321559115206
0.16436753572470753,0.41350363461955386,0.1191110629612997,0.5546038843760451
0.4779404086003456,0.26699235009794486,0.6314602368060491,0.45015079807521685
0.7526728792121127,0.6235832861546013,0.07095039872912934,0.6533879557008555
0.5431474850322893,0.612183500299674,0.1687261650843036,0.3172179764612265
0.2273371617923714,0.865680153487757,0.5827248247756568,0.07328306898709702
0.12611491247624174,0.5706376312978149,0.28098697486020496,0.9582441234112288
0.5968739274269275,0.39542100773592714,0.9988692472082709,0.37827430309233656
0.7771754323352396,0.2697182152654869,0.6403988986023146,0.32137054416117183
0.593221449278064,0.6959371750998876,0.818237870222789,0.8425875763640115
0.6150323759787362,0.8300438488533514,0.011941853213758402,0.8647488663500092
0.2029326067858479,0.2501485915782097,0.20112813726763568,0.03721096985060468
0.6863936364279091,0.3761179178286703,0.28281992377497234,0.26245689109379067
0.4965672155028681,0.7675916426266497,0.38879712109112063,0.9408961704746303
0.14110932738953297,0.7667366428562539,0.5154150569336301,0.8871155170495236
0.32517727533261,0.13810804974144586,0.8817286203276805,0.8923770435680616
0.13118415251772886,0.4724813744322741,0.6965185434293946,0.8809271527639683
0.9545553958345672,0.6911555060264112,0.3461363476444005,0.4577135252289437
0.604008641577086,0.4049278320866372,0.5576335559750655,0.4584690061172756
0.3664279387231145,0.9210977637552976,0.9259396184708046,0.6187373590686066
0.6926921671269616,0.7056455178608063,0.49433124255882477,0.7895438902447587
0.5052823855197169,0.27106020463914704,0.8116754606279196,0.13565063043789083
0.7323902276376828,0.7698002360710043,0.713490159628528,0.1641449078306726
0.13259585151529407,0.6448586999650545,0.044208192437834914,0.7185432988678314
0.8081759656453317,0.45841661860325944,0.934434925986559,0.49426593400161334
0.5771885974706991,0.5881467177722365,0.6399022163604299,0.3771869575374359
0.48758352078031464,0.318129871239599,0.9047263034728386,0.04353003454869386
0.04224832101083087,0.7216713055488719,0.7702251485607872,0.14660520157118884
0.906805106288075,0.7142423782039156,0.6492463522633645,0.8089537150363935
0.22509844113441224,0.714232692976936,0.8863034807750806,0.27751663911557733
0.927654059080697,0.9472178956834688,0.3238547493736994,0.5313974196131103
0.7775026248564839,0.366416107883324,0.8913507785084809,0.7129585365523068
0.701804618572489,0.4754051551620687,0.1483109717640092,0.9629058012646603
0.6894417967365506,0.47535612758856627,0.27065181763195223,0.419800329085256
0.7953742832102751,0.017607321320034064,0.9239257373999976,0.9132899083842303
0.8191848786683833,0.7118868982916801,0.14719023292344702,0.1464878560040236
0.045339408502298784,0.07403816709500988,0.037202775722709025,0.5006006273772845
0.3441192304926166,0.8987140282588046,0.19702093237012608,0.513983027156217
0.09985412950064898,0.38986517472782023,0.40452962687964444,0.010392375900986517
0.9888796717166685,0.7490090895916841,0.2596294186935606,0.4584345985951731
0.45700114479701004,0.6806642081959364,0.3941616551891305,0.40932639017050887
0.22870742070902517,0.4961988524015096,0.04576544412910477,0.6340760637797336
0.2919710136894722,0.23278641925489285,0.4593479168264748,0.805534031204371
0.15472055351362923,0.1326050020325038,0.30005418331448175,0.6263173704010072
0.3855935973315787,0.1600210733653037,0.1192711036086127,0.6364894057985613
0.5165874702810029,0.10589536555440149,0.836027611899695,0.5425241910064632
0.06506145636136362,0.2624350464523646,0.60599389298748,0.20824553557216086
0.5270193642446159,0.8237728230700423,0.2892156336011714,0.8873126338662943
0.18919484363192918,0.27347313781194604,0.5558426186041985,0.26130285965720756
0.9560313727021582,0.2323345531125427,0.7109228911421767,0.005298262810604415
0.5869974306959455,0.551839108711318,0.9631838302064771,0.8748224414451556
0.8394707823008176,0.14649568514521594,0.42496652865473017,0.6479642065574542
0.17595067566465916,0.27079531300287973,0.7845760830918573,0.4745584618932701
0.48854926001759913,0.1258570249789137,0.8052540177863061,0.4192898556746709
0.6212556965708542,0.39723581820451603,0.07287399150297214,0.9018901762597358
0.808743928594653,0.22119133563026316,0.25823594549123996,0.30603153212577305
0.8124836819110055,0.7059634348701986,0.13599942020850242,0.1643630702649136
0.11270816568759079,0.8985217621210186,0.604783075454661,0.5780567207297427
0.2478577942115826,0.295514530036352,0.5819979510773367,0.4515276838478285
0.9341867123294322,0.5241038121822309,0.7349093167256558,0.10821307519543244
0.9694565801743523,0.7256657249365571,0.4405418454733141,0.3452875476762217
0.6670885234356302,0.7464035693791718,0.8968707150608508,0.23460678314729688
0.8787477148217263,0.3820328244947394,0.45637968898810977,0.6485079931308289
0.6424404543524919,0.5761307478342017,0.4331408926226967,0.8070040991923705
0.8211851866370176,0.4580361289778362,0.899692936602448,0.5713664527993445
0.21206397355409146,0.3912268103159252,0.9493983929247443,0.5071785967280376
0.19406700477640937,0.6150799842880748,0.2883587772964561,0.9708823993407812
0.8040167613971719,0.6547916899574816,0.5242140387878185,0.008780205484151038
0.22082426037740743,0.11535424028214303,0.08781152460137587,0.438316057668212
0.7728123968121355,0.8042828334383247,0.778690715189286,0.38988570049482363
0.010486111694698264,0.67277991682324,0.07681804627281064,0.9567609277214955
0.2668864381442586,0.1452568826511088,0.5707392691063333,0.928043972105489
0.0306102817857985,0.9055360655368343,0.034887490136228494,0.05714269034932418
0.8886345174201701,0.7309503027420534,0.4776862370499536,0.5670174424366347
0.8382970567348228,0.34554793003082007,0.3723476159629475,0.1813898979341001
0.9047848890963807,0.7989647025237637,0.1401466580893611,0.5676980198409542
0.32257033483181474,0.867562309325832,0.9853490867984394,0.3313521730872008
0.8833118951420463,0.22198267144590023,0.4053942167679826,0.7460413091565492
0.6440770031016559,0.6146438380554794,0.2702595340451578,0.6517116434459616
0.43700087729614623,0.1956640333780958,0.6307740960622968,0.13300572762864438
0.025545984518965392,0.13259337648090797,0.330639580102997,0.6783486119187357
0.11745760865685662,0.04655297692915128,0.01570496083384365,0.3324721623808766
0.9446708945818156,0.7922202276903331,0.13532115814545032,0.5680680471004171
0.9981105344574744,0.17895387698238285,0.41489085918398205,0.9787571737165199
0.2182957368236994,0.11369398768302719,0.4712035902042646,0.5810331859747123
0.3158753508670622,0.508766658109675,0.949177716201396,0.4525860098202471
0.5260068340155828,0.7165350507158287,0.4145499033093072,0.9405637896975582
0.6270735198783227,0.014296088209979407,0.3554936000082958,0.47110739130565116
0.49216742436131966,0.7918069585203404,0.045439755466691434,0.14126827560697552
0.9551074995452985,0.7609084606692946,0.7517853978688316,0.9362533190577099
0.26649052838492904,0.10660645060167617,0.6595673397416092,0.8182263625691235
0.7134956283945861,0.792888640733119,0.16544349103619738,0.461125700665701
0.21689092404412325,0.28764631665452123,0.9657542611199962,0.9395317857593563
0.771934364979116,0.47354176406587567,0.39974739561617967,0.4672920917655088
0.055858469316713455,0.5263535147518149,0.5470407265082073,0.9196145812835027
0.3233845430037011,0.3180589338229559,0.607742422700699,0.5865738777507155
0.7652566346579441,0.581821555249569,0.5172069398211208,0.18599163645542838
0.0034684801064233106,0.2225896795781036,0.9862480175146329,0.13982000478168466
0.5017790922024837,0.40773441324079573,0.05786902177165454,0.02346346342196437
0.5899299630888499,0.9347063659987582,0.10017779286159945,0.05031189728135643
0.7552541885045175,0.8692659914400955,0.1957645607498405,0.38721358997203004
0.020654345427079224,0.5187027132180971,0.9875380926266475,0.3013184844564526
0.6514969381102048,0.46072040727750285,0.594442754475653,0.6954838811441331
0.9185130194324117,0.04293106084778964,0.8363748903511994,0.9169946702125765
0.01575990734707533,0.6247692943585893,0.09038267623487206,0.05157924280558712
0.8607637728932239,0.9736616782275902,0.08111827087665802,0.8665656920735859
0.666744972708363,0.7696471975946282,0.6545167483950083,0.1836352141094666
0.14890415384126243,0.5882642074433254,0.47488324034977136,0.1401242764796421
0.9226772234533692,0.5110406596658441,0.5694788038165256,0.7467927879198694
0.21131539061769633,0.6825600857581313,0.7125768055425141,0.40832581447694716
0.6067351237433124,0.5936720758765013,0.12956326274296215,0.39895208390744263
0.07503423810335952,0.7692901398814894,0.5080248598788042,0.1132694830734321
0.6779853647179561,0.8785368744942339,0.2449159217780239,0.6984978366100005
0.5639290842821031,0.13429933931245086,0.41879712608263253,0.11511037033327509
0.4771948700443285,0.66869023375205,0.09436736601701601,0.2832346511771564
0.11389507788099285,0.9548819478014735,0.43162079915995966,0.13260141339156495
0.6933840471420535,0.8569772316175522,0.9438136873946976,0.2550298038407348
0.7667432308405324,0.7092661191253911,0.20467525417272814,0.00409058163964926
0.6033640307046173,0.5194782580436552,0.269802344368703,0.0252733853595154
0.7500958618175847,0.6816089568443191,0.06288441532040989,0.6625546198107677
0.14076814361824563,0.4000247200283372,0.3986400215241256,0.862359520497777
0.909050353083993,0.734140757406571,0.20627521456988696,0.022666933456822025
0.14164469015917447,0.46663482555229896,0.19226649392802975,0.6895759193711927
0.6384146831254898,0.8267776768248442,0.8248241916927097,0.9667913170456913
0.5995286449654652,0.6128661292930289,0.8076508959412709,0.5643091139270656
0.3660885061550925,0.6516894443881318,0.08279706016975263,0.02494681579030067
0.5343084901999381,0.4490041029823132,0.5485797015135121,0.8770746060099789
0.7591888502765555,0.7641772821881035,0.8627631867464572,0.790588149387367
0.11646298257714938,0.712586114834284,0.17850893843707638,0.0499046100449253
0.5736399771896279,0.24779945904696066,0.8353495305737935,0.6098353636118041
0.39995891099221725,0.38755138066544736,0.3206667889777627,0.8621821104916472
0.16963442693178976,0.1655588529460691,0.00471004269840658,0.03680381149038636
0.8913913191956618,0.4931553146014762,0.7212555101341884,0.535167989549179
0.19260952114367957,0.8894977792750658,0.9277896033411086,0.9266292288349561
0.8024400170720553,0.15728226403474244,0.6311310614764399,0.8940669250997342
0.13040641009710163,0.47598924174257407,0.4047476679695895,0.8151863456470257
0.9904753132378885,0.1929664786631008,0.6649932127466588,0.3890716243782475
0.06835950232326915,0.9179509323620376,0.9997085419499564,0.005016089384341504
0.2284112907168191,0.20349570495715097,0.9053407127073567,0.29129471127644957
0.23807412297897446,0.7433707240814856,0.2797207561532188,0.7055119549347723
0.2980015747932633,0.1528124911964729,0.2922351758608043,0.4744831732503145
0.9323151646558789,0.9016005665933837,0.04859295723828494,0.40406758360182427
0.0020015859464498353,0.8573856734531015,0.835630618879145,0.27134674911444545
0.6476158569481719,0.7619325435307918,0.9387844644429776,0.5025693523387598
0.35712967268125584,0.35535013097389045,0.6846636602836755,0.3529193027458817
0.9528744981293424,0.907004048138501,0.7922686555445306,0.6442300435823645
0.42594045350938714,0.7635686751066307,0.039866196100581064,0.8501629086487204
0.16151992349458166,0.027644573646974036,0.9940414223507111,0.30145531751034094
0.8192631972556896,0.5315304397102365,0.8819242518354289,0.7140853094035905
0.3640049949086881,0.8916802473396235,0.610690893660492,0.19860084943122835
0.03241401801078403,0.5997948103711187,0.3459077815858529,0.8429274697369962
0.860296620923188,0.7498450748611823,0.724915922543078,0.3674775151021594
0.12479747320689649,0.790080464590465,0.5590618642994262,0.695729010767191
0.4226547764778965,0.7662131047806842,0.0314974785100639,0.7126390471593306
0.717960945501675,0.44433663986840155,0.7338197075921654,0.6198705088373945
0.9130079792319507,0.388142201662786,0.9204914884121788,0.7782865287937031
0.9446157546353985,0.8229203898981865,0.37815408733881994,0.9474516986216488
0.4692270195228362,0.3624411531029099,0.9440792553003939,0.6632688289247249
0.35729593281341854,0.09094931962987118,0.6894993679786272,0.6604239544162929
0.8295230947269575,0.37987043680523425,0.21978418081773277,0.9845319112288327
0.9054097736788218,0.6795244920749846,0.8058227024795273,0.8620535192255319
0.47206954649038335,0.9877578985324961,0.31200381383209264,0.4274016880635737
0.3788613590960972,0.228409024641122,0.19313897647932965,0.534690513837352
0.80232246756088,0.2998305554602545,0.2302798655782391,0.3728021218773693
0.2304818792066189,0.6705989422124993,0.7782382571611371,0.4145383754064982
0.7865979675238535,0.6256642699276077,0.6975970325705699,0.3304703930316044
0.2804152526765058,0.7506842663153662,0.935091785948748,0.8731861911602196
0.7733320316872647,0.06830631213470884,0.727537718955761,0.8243956447692756
0.8000717021921332,0.9827480235866367,0.10931315443917511,0.7646403326087104
0.15901650211578955,0.9607869193069879,0.7672418492405033,0.8857690961012441
0.39077830713874184,0.26566502812783865,0.7247651263316303,0.870345905475203
0.468444105096292,0.5035851734032031,0.7273267277987141,0.4386595809446233
0.6082661742527247,0.8835487968537153,0.2648075784103565,0.5097528202982465
0.1688589216994002,0.4587933228957092,0.06822389196178069,0.6944061276912664
0.8845023251920414,0.35626742579837833,0.24854712468804263,0.9286656126601583
0.6919912900325229,0.525926779915432,0.5028362151137027,0.7758761895796565
0.09072890731788164,0.2754248703653789,0.8794450999976556,0.5929425050351603
0.8045417151161639,0.717332184240045,0.4009746132815435,0.3576329066088556
0.8592956140479793,0.8885466867456595,0.6652781416892141,0.46618925902384434
0.9406255815435112,0.9535348493796136,0.8566780449450918,0.09147572622405076
0.21134438575825976,0.37870907194098735,0.8918450302424455,0.8756071157265357
0.17056446131279757,0.5947167672181617,0.42713739170980713,0.8231253767701853
0.6816965030835896,0.9174242883534593,0.9433745514214174,0.3850430220570764
0.13200731308338776,0.9544252195264228,0.9253057443590936,0.17330980292668996
0.1797299073809655,0.5798737456579879,0.4904506542903413,0.07273516539361113
0.4686355912210618,0.15029444542816606,0.46278071678091204,0.8070448038422068
0.7574896574957928,0.982488939171607,0.48131438961476347,0.25693746632683634
0.9031624053831494,0.6540179859697732,0.5756477983878667,0.900018098502001
0.706778868235879,0.5290013506815173,0.27214577830929343,0.6480582221558611
0.5257555048131995,0.8202277041197588,0.9755252443363349,0.09150668990330679
0.2941118779304933,0.3160354013957346,0.07938351200005711,0.9284536477999036
0.3739355906627365,0.03654420156550575,0.6739743288835183,0.9528120972614034
0.29419616996955233,0.5180544099970837,0.9045835653031059,0.7490505883308898
0.5310119647704037,0.6208203267999307,0.4742606286491172,0.3676507758811156
0.5125560598459081,0.7230868177919499,0.21690326890395972,0.7029765452094612
0.2327168465092495,0.636427765358658,0.2795775063082444,0.2811043827126858
0.8979887687291225,0.1998743986080337,0.0861396746346903,0.9648494063439969
0.12944581215276862,0.7281358241811274,0.8211700518321551,0.14249279838367745
0.5248705106310002,0.05235202234421987,0.6947375170266925,0.3417365273756968
0.10595743196582197,0.07826617709938821,0.35337783398376776,0.4264573065236815
0.050009605714936844,0.018514896667227054,0.9413608402598351,0.791610587209869
0.17864320609241946,0.31880728783473555,0.6071840694245375,0.8248621694108086
0.9414648897887672,0.47850303480223844,0.5188440720457512,0.35654133260507215
0.12219561454685202,0.22693565011856753,0.7331870796269597,0.0028505501610355255
0.5716554932588412,0.6233114983745688,0.5790584042092602,0.2773603020533283
0.1730667946075105,0.4564347627258698,0.862108197216226,0.27326576204651987
0.10099838707719744,0.8963154205564153,0.2995006490737322,0.2507624147096721
0.2215100698131235,0.2096828648871747,0.1735729661494131,0.9037812640080347
0.3330121683438939,0.26772071803392583,0.1360347053953318,0.6143336229667071
0.8755253114603656,0.44786236422952297,0.5069228872958722,0.176168922805505
0.4360566521753333,0.8249506306465185,0.6928263688828447,0.9157745831809156
0.7044681125246586,0.7095402004346812,0.05729221320115585,0.03404868292678953
0.8839520510806439,0.6504324482442831,0.3794442442167103,0.21418711025841375
0.3967513210941327,0.3325872301281432,0.31405878752308436,0.07799771452864457
0.7015490555702932,0.5156822991121691,0.23180117678821388,0.7166130112807891
0.8214439604906325,0.4407717872048116,0.37329993356057734,0.06083737830173952
0.38149071192905015,0.7550155142103253,0.460697700554616,0.2796872439634027
0.4810015127837912,0.5713080743424898,0.9571267966357225,0.7911382384952027
0.13998304353038438,0.3347918696327902,0.39657017898620517,0.5270438421014269
0.4043555405999496,0.5788249986243309,0.12586900730635686,0.3861265257391172
0.8389573878855994,0.888492299987596,0.8540078803737782,0.25800593264854366
0.567489926995696,0.39357032152193006,0.5123037666069444,0.08297825613816934
0.6649010291920261,0.5047397206924729,0.44553780850164726,0.08797176467481449
0.7419214077622256,0.12624259595301301,0.9996070355531719,0.06564068719726601
0.32057166076285726,0.31659935778593506,0.1545928953280743,0.8581764856647075
0.09301334726876975,0.029335007802145707,0.6565556741127787,0.5739346723086256
0.04526245346044655,0.811778405905253,0.5066344307977078,0.8059965416628634
0.8019082608898042,0.10700897299954537,0.7204698407553198,0.7683031150791029
0.020961990206823322,0.42518192744827077,0.255974197387997,0.7306897745495752
0.277961915387847,0.8492620182849753,0.34537132250463576,0.15943780211188874
0.7189442674847957,0.8200795519063174,0.5656964635313514,0.3874546949307659
0.8268401141848842,0.23386593281804413,0.2845078924626273,0.9406006062017659
0.23039240497397429,0.761442391428125,0.9392894531292257,0.9085208491905314
0.29838729188215807,0.5779838410486858,0.8325117429343363,0.9899463893352769
0.8326874856620977,0.4784419176424144,0.4577629375969198,0.6361698618474226
0.22261035955598107,0.7416746800534105,0.2454421585188994,0.58078567230664
0.9571491019691408,0.6511369553101578,0.411185456458281,0.8662214279916548
0.2824314672551116,0.4507337840870643,0.7588600505511918,0.003965656234663606
0.07051188316677992,0.4761351008427914,0.5804476241986976,0.3893672504249296
0.6041561817793055,0.8835940935113349,0.8868809585790102,0.49618477971384356
0.6759397175203108,0.034009359158778896,0.45914373245374573,0.281948988195467
0.5848526420565103,0.0630186414631515,0.7352196908090805,0.8726649542656703
0.35400058269043266,0.3903304091964207,0.7778206460661615,0.2963873440073307
0.25238414291129874,0.5984939737976703,0.17745813410050737,0.05300754434656185
0.4954938296688921,0.05875264031148697,0.39350417074169364,0.4328594911628031
0.9197968567238212,0.5157119691395418,0.033718530566680616,0.5043298885605011
0.2989332113820844,0.7034343832601815,0.2026921006487793,0.6432289937302853
0.7779676202913468,0.610689301839738,0.9000420564430714,0.02779597067857109
0.6904833489696073,0.2790190885678663,0.09485751900588535,0.8814594722251355
0.5235313634791201,0.23610058713680604,0.9546586611291935,0.3497260033438957
0.11341445111776471,0.24283712840412264,0.9337047983116655,0.6507089882891222
0.6881809970467796,0.5354244135798761,0.07696211613601234,0.42662334179962424
0.6924697609000138,0.23785520913895875,0.8706017587442036,0.07581266371719819
0.528704746140301,0.22612181722433033,0.055834654502542325,0.1319617598033216
0.3247295924286646,0.21520112383699908,0.9353024163591054,0.7941147979952861
0.1180358736188245,0.2645743905840382,0.6292058447395664,0.8240620030300988
0.227021327823424,0.6602085012760409,0.8513526298900511,0.4786758954200979
0.4661570022497308,0.7529998155162079,0.11539087183657204,0.27971183920107534

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,502 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pandas Datareader\n",
"\n",
"** NOTE: Not every geographical location works well with pandas datareader, your firewall may also block it!**\n",
"\n",
"Functions from pandas_datareader.data and pandas_datareader.wb extract data from various Internet sources into a pandas DataFrame. Currently the following sources are supported:\n",
"\n",
"* Yahoo! Finance\n",
"* Google Finance\n",
"* Enigma\n",
"* St.Louis FED (FRED)\n",
"* Kenneth Frenchs data library\n",
"* World Bank\n",
"* OECD\n",
"* Eurostat\n",
"* Thrift Savings Plan\n",
"* Oanda currency historical rate\n",
"* Nasdaq Trader symbol definitions (remote_data.nasdaq_symbols)\n",
"\n",
"It should be noted, that various sources support different kinds of data, so not all sources implement the same methods and the data elements returned might also differ."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas_datareader.data as web\n",
"\n",
"import datetime\n",
"\n",
"start = datetime.datetime(2015, 1, 1)\n",
"\n",
"end = datetime.datetime(2017, 1, 1)\n",
"\n",
"facebook = web.DataReader(\"FB\", 'google', start, end)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Volume</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2015-01-02</th>\n",
" <td>78.58</td>\n",
" <td>78.93</td>\n",
" <td>77.70</td>\n",
" <td>78.45</td>\n",
" <td>18177475</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2015-01-05</th>\n",
" <td>77.98</td>\n",
" <td>79.25</td>\n",
" <td>76.86</td>\n",
" <td>77.19</td>\n",
" <td>26452191</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2015-01-06</th>\n",
" <td>77.23</td>\n",
" <td>77.59</td>\n",
" <td>75.36</td>\n",
" <td>76.15</td>\n",
" <td>27399288</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2015-01-07</th>\n",
" <td>76.76</td>\n",
" <td>77.36</td>\n",
" <td>75.82</td>\n",
" <td>76.15</td>\n",
" <td>22045333</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2015-01-08</th>\n",
" <td>76.74</td>\n",
" <td>78.23</td>\n",
" <td>76.08</td>\n",
" <td>78.18</td>\n",
" <td>23960953</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Open High Low Close Volume\n",
"Date \n",
"2015-01-02 78.58 78.93 77.70 78.45 18177475\n",
"2015-01-05 77.98 79.25 76.86 77.19 26452191\n",
"2015-01-06 77.23 77.59 75.36 76.15 27399288\n",
"2015-01-07 76.76 77.36 75.82 76.15 22045333\n",
"2015-01-08 76.74 78.23 76.08 78.18 23960953"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"facebook.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Experimental Options\n",
"\n",
"The Options class allows the download of options data from Google Finance.\n",
"\n",
"The get_options_data method downloads options data for specified expiry date and provides a formatted DataFrame with a hierarchical index, so its easy to get to the specific option you want.\n",
"\n",
"Available expiry dates can be accessed from the expiry_dates property."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from pandas_datareader.data import Options\n",
"\n",
"fb_options = Options('FB', 'google')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"data = fb_options.get_options_data(expiry=fb_options.expiry_dates[0])"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\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></th>\n",
" <th></th>\n",
" <th>Last</th>\n",
" <th>Bid</th>\n",
" <th>Ask</th>\n",
" <th>Chg</th>\n",
" <th>PctChg</th>\n",
" <th>Vol</th>\n",
" <th>Open_Int</th>\n",
" <th>Root</th>\n",
" <th>Underlying_Price</th>\n",
" <th>Quote_Time</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Strike</th>\n",
" <th>Expiry</th>\n",
" <th>Type</th>\n",
" <th>Symbol</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">5.0</th>\n",
" <th rowspan=\"2\" valign=\"top\">2018-01-19</th>\n",
" <th>call</th>\n",
" <th>FB180119C00005000</th>\n",
" <td>149.10</td>\n",
" <td>150.00</td>\n",
" <td>150.65</td>\n",
" <td>0.3</td>\n",
" <td>0.20</td>\n",
" <td>50.0</td>\n",
" <td>9528.0</td>\n",
" <td>FB</td>\n",
" <td>155.27</td>\n",
" <td>2017-07-11 23:35:24.466303</td>\n",
" </tr>\n",
" <tr>\n",
" <th>put</th>\n",
" <th>FB180119P00005000</th>\n",
" <td>0.01</td>\n",
" <td>NaN</td>\n",
" <td>0.03</td>\n",
" <td>0.0</td>\n",
" <td>0.00</td>\n",
" <td>NaN</td>\n",
" <td>3053.0</td>\n",
" <td>FB</td>\n",
" <td>155.27</td>\n",
" <td>2017-07-11 23:35:24.466303</td>\n",
" </tr>\n",
" <tr>\n",
" <th rowspan=\"2\" valign=\"top\">10.0</th>\n",
" <th rowspan=\"2\" valign=\"top\">2018-01-19</th>\n",
" <th>call</th>\n",
" <th>FB180119C00010000</th>\n",
" <td>143.20</td>\n",
" <td>145.05</td>\n",
" <td>145.75</td>\n",
" <td>-0.5</td>\n",
" <td>-0.35</td>\n",
" <td>40.0</td>\n",
" <td>2855.0</td>\n",
" <td>FB</td>\n",
" <td>155.27</td>\n",
" <td>2017-07-11 23:35:24.466303</td>\n",
" </tr>\n",
" <tr>\n",
" <th>put</th>\n",
" <th>FB180119P00010000</th>\n",
" <td>0.01</td>\n",
" <td>NaN</td>\n",
" <td>0.02</td>\n",
" <td>0.0</td>\n",
" <td>0.00</td>\n",
" <td>NaN</td>\n",
" <td>2056.0</td>\n",
" <td>FB</td>\n",
" <td>155.27</td>\n",
" <td>2017-07-11 23:35:24.466303</td>\n",
" </tr>\n",
" <tr>\n",
" <th>15.0</th>\n",
" <th>2018-01-19</th>\n",
" <th>call</th>\n",
" <th>FB180119C00015000</th>\n",
" <td>135.80</td>\n",
" <td>140.10</td>\n",
" <td>140.80</td>\n",
" <td>0.0</td>\n",
" <td>0.00</td>\n",
" <td>NaN</td>\n",
" <td>240.0</td>\n",
" <td>FB</td>\n",
" <td>155.27</td>\n",
" <td>2017-07-11 23:35:24.466303</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Last Bid Ask Chg PctChg \\\n",
"Strike Expiry Type Symbol \n",
"5.0 2018-01-19 call FB180119C00005000 149.10 150.00 150.65 0.3 0.20 \n",
" put FB180119P00005000 0.01 NaN 0.03 0.0 0.00 \n",
"10.0 2018-01-19 call FB180119C00010000 143.20 145.05 145.75 -0.5 -0.35 \n",
" put FB180119P00010000 0.01 NaN 0.02 0.0 0.00 \n",
"15.0 2018-01-19 call FB180119C00015000 135.80 140.10 140.80 0.0 0.00 \n",
"\n",
" Vol Open_Int Root \\\n",
"Strike Expiry Type Symbol \n",
"5.0 2018-01-19 call FB180119C00005000 50.0 9528.0 FB \n",
" put FB180119P00005000 NaN 3053.0 FB \n",
"10.0 2018-01-19 call FB180119C00010000 40.0 2855.0 FB \n",
" put FB180119P00010000 NaN 2056.0 FB \n",
"15.0 2018-01-19 call FB180119C00015000 NaN 240.0 FB \n",
"\n",
" Underlying_Price \\\n",
"Strike Expiry Type Symbol \n",
"5.0 2018-01-19 call FB180119C00005000 155.27 \n",
" put FB180119P00005000 155.27 \n",
"10.0 2018-01-19 call FB180119C00010000 155.27 \n",
" put FB180119P00010000 155.27 \n",
"15.0 2018-01-19 call FB180119C00015000 155.27 \n",
"\n",
" Quote_Time \n",
"Strike Expiry Type Symbol \n",
"5.0 2018-01-19 call FB180119C00005000 2017-07-11 23:35:24.466303 \n",
" put FB180119P00005000 2017-07-11 23:35:24.466303 \n",
"10.0 2018-01-19 call FB180119C00010000 2017-07-11 23:35:24.466303 \n",
" put FB180119P00010000 2017-07-11 23:35:24.466303 \n",
"15.0 2018-01-19 call FB180119C00015000 2017-07-11 23:35:24.466303 "
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"data.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# FRED"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas_datareader.data as web\n",
"\n",
"import datetime\n",
"\n",
"start = datetime.datetime(2010, 1, 1)\n",
"\n",
"end = datetime.datetime(2017, 1, 1)\n",
"\n",
"gdp = web.DataReader(\"GDP\", \"fred\", start, end)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style>\n",
" .dataframe thead tr:only-child th {\n",
" text-align: right;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: left;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>GDP</th>\n",
" </tr>\n",
" <tr>\n",
" <th>DATE</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2010-01-01</th>\n",
" <td>14681.1</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-04-01</th>\n",
" <td>14888.6</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-07-01</th>\n",
" <td>15057.7</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-10-01</th>\n",
" <td>15230.2</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2011-01-01</th>\n",
" <td>15238.4</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" GDP\n",
"DATE \n",
"2010-01-01 14681.1\n",
"2010-04-01 14888.6\n",
"2010-07-01 15057.7\n",
"2010-10-01 15230.2\n",
"2011-01-01 15238.4"
]
},
"execution_count": 12,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdp.head()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"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.6.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,279 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Pandas Datareader\n",
"\n",
"**EMARQUE : Tous les emplacements géographiques ne fonctionnent pas bien avec le lecteur de données pandas, votre pare-feu peut aussi le bloquer !**\n",
"\n",
"Les fonctions de pandas_datareader.data et pandas_datareader.wb extraient les données de diverses sources Internet dans un DataFrame pandas. Actuellement, les sources suivantes sont supportées :\n",
"\n",
"* Yahoo! Finance\n",
"* Enigma\n",
"* St.Louis FED (FRED)\n",
"* Kenneth Frenchs data library\n",
"* World Bank\n",
"* OECD\n",
"* Eurostat\n",
"* Thrift Savings Plan\n",
"* Oanda currency historical rate\n",
"* Nasdaq Trader symbol definitions (remote_data.nasdaq_symbols)\n",
"\n",
"Il convient de noter que diverses sources soutiennent différents types de données, de sorte que toutes les sources n'appliquent pas les mêmes méthodes et que les éléments de données retournés peuvent également différer."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas_datareader.data as web\n",
"\n",
"import datetime\n",
"\n",
"start = datetime.datetime(2015, 1, 1)\n",
"\n",
"end = datetime.datetime(2017, 1, 1)\n",
"\n",
"facebook = web.DataReader(\"FB\", 'yahoo', start, end)"
]
},
{
"cell_type": "code",
"execution_count": 2,
"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>High</th>\n",
" <th>Low</th>\n",
" <th>Open</th>\n",
" <th>Close</th>\n",
" <th>Volume</th>\n",
" <th>Adj Close</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2015-01-02</th>\n",
" <td>78.930000</td>\n",
" <td>77.699997</td>\n",
" <td>78.580002</td>\n",
" <td>78.449997</td>\n",
" <td>18177500</td>\n",
" <td>78.449997</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2015-01-05</th>\n",
" <td>79.250000</td>\n",
" <td>76.860001</td>\n",
" <td>77.980003</td>\n",
" <td>77.190002</td>\n",
" <td>26452200</td>\n",
" <td>77.190002</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2015-01-06</th>\n",
" <td>77.589996</td>\n",
" <td>75.360001</td>\n",
" <td>77.230003</td>\n",
" <td>76.150002</td>\n",
" <td>27399300</td>\n",
" <td>76.150002</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2015-01-07</th>\n",
" <td>77.360001</td>\n",
" <td>75.820000</td>\n",
" <td>76.760002</td>\n",
" <td>76.150002</td>\n",
" <td>22045300</td>\n",
" <td>76.150002</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2015-01-08</th>\n",
" <td>78.230003</td>\n",
" <td>76.080002</td>\n",
" <td>76.739998</td>\n",
" <td>78.180000</td>\n",
" <td>23961000</td>\n",
" <td>78.180000</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" High Low Open Close Volume Adj Close\n",
"Date \n",
"2015-01-02 78.930000 77.699997 78.580002 78.449997 18177500 78.449997\n",
"2015-01-05 79.250000 76.860001 77.980003 77.190002 26452200 77.190002\n",
"2015-01-06 77.589996 75.360001 77.230003 76.150002 27399300 76.150002\n",
"2015-01-07 77.360001 75.820000 76.760002 76.150002 22045300 76.150002\n",
"2015-01-08 78.230003 76.080002 76.739998 78.180000 23961000 78.180000"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"facebook.head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# FRED"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"import pandas_datareader.data as web\n",
"\n",
"import datetime\n",
"\n",
"start = datetime.datetime(2010, 1, 1)\n",
"\n",
"end = datetime.datetime(2017, 1, 1)\n",
"\n",
"gdp = web.DataReader(\"GDP\", \"fred\", start, end)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"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>GDP</th>\n",
" </tr>\n",
" <tr>\n",
" <th>DATE</th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2010-01-01</th>\n",
" <td>14721.350</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-04-01</th>\n",
" <td>14926.098</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-07-01</th>\n",
" <td>15079.917</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2010-10-01</th>\n",
" <td>15240.843</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2011-01-01</th>\n",
" <td>15285.828</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" GDP\n",
"DATE \n",
"2010-01-01 14721.350\n",
"2010-04-01 14926.098\n",
"2010-07-01 15079.917\n",
"2010-10-01 15240.843\n",
"2011-01-01 15285.828"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"gdp.head()"
]
}
],
"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.7.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,467 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>\n",
"___\n",
"<center>*Copyright Pierian Data 2017*</center>\n",
"<center>*For more information, visit us at www.pieriandata.com*</center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction to Time Series with Pandas\n",
"\n",
"A lot of our financial data will have a datatime index, so let's learn how to deal with this sort of data with pandas!"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from datetime import datetime"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# To illustrate the order of arguments\n",
"my_year = 2017\n",
"my_month = 1\n",
"my_day = 2\n",
"my_hour = 13\n",
"my_minute = 30\n",
"my_second = 15"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"# January 2nd, 2017\n",
"my_date = datetime(my_year,my_month,my_day)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2017, 1, 2, 0, 0)"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Defaults to 0:00\n",
"my_date "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"# January 2nd, 2017 at 13:30:15\n",
"my_date_time = datetime(my_year,my_month,my_day,my_hour,my_minute,my_second)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"datetime.datetime(2017, 1, 2, 13, 30, 15)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_date_time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"You can grab any part of the datetime object you want"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"2"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_date.day"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"13"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"my_date_time.hour"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Pandas with Datetime Index\n",
"\n",
"You'll usually deal with time series as an index when working with pandas dataframes obtained from some sort of financial API. Fortunately pandas has a lot of functions and methods to work with time series!"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"[datetime.datetime(2016, 1, 1, 0, 0), datetime.datetime(2016, 1, 2, 0, 0)]"
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Create an example datetime list/array\n",
"first_two = [datetime(2016, 1, 1), datetime(2016, 1, 2)]\n",
"first_two"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"DatetimeIndex(['2016-01-01', '2016-01-02'], dtype='datetime64[ns]', freq=None)"
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Converted to an index\n",
"dt_ind = pd.DatetimeIndex(first_two)\n",
"dt_ind"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[[-1.58270607 0.47766839]\n",
" [ 0.34171008 0.5889566 ]]\n"
]
}
],
"source": [
"# Attached to some random data\n",
"data = np.random.randn(2,2)\n",
"print(data)\n",
"cols = ['A','B']"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df = pd.DataFrame(data,dt_ind,cols)"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\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",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2016-01-01</th>\n",
" <td>0.165224</td>\n",
" <td>-0.767629</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-01-02</th>\n",
" <td>-0.482305</td>\n",
" <td>0.307934</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" A B\n",
"2016-01-01 0.165224 -0.767629\n",
"2016-01-02 -0.482305 0.307934"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"DatetimeIndex(['2016-01-01', '2016-01-02'], dtype='datetime64[ns]', freq=None)"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.index"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"1"
]
},
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Latest Date Location\n",
"df.index.argmax()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2016-01-02 00:00:00')"
]
},
"execution_count": 35,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.index.max()"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Earliest Date Index Location\n",
"df.index.argmin()"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"Timestamp('2016-01-01 00:00:00')"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.index.min()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Great, let's move on!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"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.5.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

View File

@ -0,0 +1,811 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"___\n",
"\n",
"<a href='http://www.pieriandata.com'> <img src='../Pierian_Data_Logo.png' /></a>\n",
"___\n",
"<center>*Copyright Pierian Data 2017*</center>\n",
"<center>*For more information, visit us at www.pieriandata.com*</center>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Time Shifting\n",
"\n",
"Sometimes you may need to shift all your data up or down along the time series index, in fact, a lot of pandas built-in methods do this under the hood. This isn't something we won't do often in the course, but its definitely good to know about this anyways!"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"df = pd.read_csv('time_data/walmart_stock.csv',index_col='Date')\n",
"df.index = pd.to_datetime(df.index)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Volume</th>\n",
" <th>Adj Close</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2012-01-03</th>\n",
" <td>59.970001</td>\n",
" <td>61.060001</td>\n",
" <td>59.869999</td>\n",
" <td>60.330002</td>\n",
" <td>12668800</td>\n",
" <td>52.619235</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-04</th>\n",
" <td>60.209999</td>\n",
" <td>60.349998</td>\n",
" <td>59.470001</td>\n",
" <td>59.709999</td>\n",
" <td>9593300</td>\n",
" <td>52.078475</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-05</th>\n",
" <td>59.349998</td>\n",
" <td>59.619999</td>\n",
" <td>58.369999</td>\n",
" <td>59.419998</td>\n",
" <td>12768200</td>\n",
" <td>51.825539</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-06</th>\n",
" <td>59.419998</td>\n",
" <td>59.450001</td>\n",
" <td>58.869999</td>\n",
" <td>59.000000</td>\n",
" <td>8069400</td>\n",
" <td>51.459220</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-09</th>\n",
" <td>59.029999</td>\n",
" <td>59.549999</td>\n",
" <td>58.919998</td>\n",
" <td>59.180000</td>\n",
" <td>6679300</td>\n",
" <td>51.616215</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2012-01-03 59.970001 61.060001 59.869999 60.330002 12668800 52.619235\n",
"2012-01-04 60.209999 60.349998 59.470001 59.709999 9593300 52.078475\n",
"2012-01-05 59.349998 59.619999 58.369999 59.419998 12768200 51.825539\n",
"2012-01-06 59.419998 59.450001 58.869999 59.000000 8069400 51.459220\n",
"2012-01-09 59.029999 59.549999 58.919998 59.180000 6679300 51.616215"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Volume</th>\n",
" <th>Adj Close</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2016-12-23</th>\n",
" <td>69.430000</td>\n",
" <td>69.750000</td>\n",
" <td>69.360001</td>\n",
" <td>69.540001</td>\n",
" <td>4803900</td>\n",
" <td>69.032411</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-27</th>\n",
" <td>69.300003</td>\n",
" <td>69.820000</td>\n",
" <td>69.250000</td>\n",
" <td>69.699997</td>\n",
" <td>4435700</td>\n",
" <td>69.191240</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-28</th>\n",
" <td>69.940002</td>\n",
" <td>70.000000</td>\n",
" <td>69.260002</td>\n",
" <td>69.309998</td>\n",
" <td>4875700</td>\n",
" <td>68.804087</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-29</th>\n",
" <td>69.209999</td>\n",
" <td>69.519997</td>\n",
" <td>69.120003</td>\n",
" <td>69.260002</td>\n",
" <td>4298400</td>\n",
" <td>68.754456</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-30</th>\n",
" <td>69.120003</td>\n",
" <td>69.430000</td>\n",
" <td>68.830002</td>\n",
" <td>69.120003</td>\n",
" <td>6889500</td>\n",
" <td>68.615479</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2016-12-23 69.430000 69.750000 69.360001 69.540001 4803900 69.032411\n",
"2016-12-27 69.300003 69.820000 69.250000 69.699997 4435700 69.191240\n",
"2016-12-28 69.940002 70.000000 69.260002 69.309998 4875700 68.804087\n",
"2016-12-29 69.209999 69.519997 69.120003 69.260002 4298400 68.754456\n",
"2016-12-30 69.120003 69.430000 68.830002 69.120003 6889500 68.615479"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.tail()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## .shift() forward"
]
},
{
"cell_type": "code",
"execution_count": 23,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Volume</th>\n",
" <th>Adj Close</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2012-01-03</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-04</th>\n",
" <td>59.970001</td>\n",
" <td>61.060001</td>\n",
" <td>59.869999</td>\n",
" <td>60.330002</td>\n",
" <td>12668800.0</td>\n",
" <td>52.619235</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-05</th>\n",
" <td>60.209999</td>\n",
" <td>60.349998</td>\n",
" <td>59.470001</td>\n",
" <td>59.709999</td>\n",
" <td>9593300.0</td>\n",
" <td>52.078475</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-06</th>\n",
" <td>59.349998</td>\n",
" <td>59.619999</td>\n",
" <td>58.369999</td>\n",
" <td>59.419998</td>\n",
" <td>12768200.0</td>\n",
" <td>51.825539</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-09</th>\n",
" <td>59.419998</td>\n",
" <td>59.450001</td>\n",
" <td>58.869999</td>\n",
" <td>59.000000</td>\n",
" <td>8069400.0</td>\n",
" <td>51.459220</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2012-01-03 NaN NaN NaN NaN NaN NaN\n",
"2012-01-04 59.970001 61.060001 59.869999 60.330002 12668800.0 52.619235\n",
"2012-01-05 60.209999 60.349998 59.470001 59.709999 9593300.0 52.078475\n",
"2012-01-06 59.349998 59.619999 58.369999 59.419998 12768200.0 51.825539\n",
"2012-01-09 59.419998 59.450001 58.869999 59.000000 8069400.0 51.459220"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.shift(1).head()"
]
},
{
"cell_type": "code",
"execution_count": 24,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Volume</th>\n",
" <th>Adj Close</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2016-12-23</th>\n",
" <td>71.239998</td>\n",
" <td>71.239998</td>\n",
" <td>69.209999</td>\n",
" <td>69.589996</td>\n",
" <td>12106800.0</td>\n",
" <td>69.082042</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-27</th>\n",
" <td>69.430000</td>\n",
" <td>69.750000</td>\n",
" <td>69.360001</td>\n",
" <td>69.540001</td>\n",
" <td>4803900.0</td>\n",
" <td>69.032411</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-28</th>\n",
" <td>69.300003</td>\n",
" <td>69.820000</td>\n",
" <td>69.250000</td>\n",
" <td>69.699997</td>\n",
" <td>4435700.0</td>\n",
" <td>69.191240</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-29</th>\n",
" <td>69.940002</td>\n",
" <td>70.000000</td>\n",
" <td>69.260002</td>\n",
" <td>69.309998</td>\n",
" <td>4875700.0</td>\n",
" <td>68.804087</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-30</th>\n",
" <td>69.209999</td>\n",
" <td>69.519997</td>\n",
" <td>69.120003</td>\n",
" <td>69.260002</td>\n",
" <td>4298400.0</td>\n",
" <td>68.754456</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2016-12-23 71.239998 71.239998 69.209999 69.589996 12106800.0 69.082042\n",
"2016-12-27 69.430000 69.750000 69.360001 69.540001 4803900.0 69.032411\n",
"2016-12-28 69.300003 69.820000 69.250000 69.699997 4435700.0 69.191240\n",
"2016-12-29 69.940002 70.000000 69.260002 69.309998 4875700.0 68.804087\n",
"2016-12-30 69.209999 69.519997 69.120003 69.260002 4298400.0 68.754456"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# You will lose that last piece of data that no longer has an index!\n",
"df.shift(1).tail()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## shift() backwards"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Volume</th>\n",
" <th>Adj Close</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2012-01-03</th>\n",
" <td>60.209999</td>\n",
" <td>60.349998</td>\n",
" <td>59.470001</td>\n",
" <td>59.709999</td>\n",
" <td>9593300.0</td>\n",
" <td>52.078475</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-04</th>\n",
" <td>59.349998</td>\n",
" <td>59.619999</td>\n",
" <td>58.369999</td>\n",
" <td>59.419998</td>\n",
" <td>12768200.0</td>\n",
" <td>51.825539</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-05</th>\n",
" <td>59.419998</td>\n",
" <td>59.450001</td>\n",
" <td>58.869999</td>\n",
" <td>59.000000</td>\n",
" <td>8069400.0</td>\n",
" <td>51.459220</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-06</th>\n",
" <td>59.029999</td>\n",
" <td>59.549999</td>\n",
" <td>58.919998</td>\n",
" <td>59.180000</td>\n",
" <td>6679300.0</td>\n",
" <td>51.616215</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-09</th>\n",
" <td>59.430000</td>\n",
" <td>59.709999</td>\n",
" <td>58.980000</td>\n",
" <td>59.040001</td>\n",
" <td>6907300.0</td>\n",
" <td>51.494109</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2012-01-03 60.209999 60.349998 59.470001 59.709999 9593300.0 52.078475\n",
"2012-01-04 59.349998 59.619999 58.369999 59.419998 12768200.0 51.825539\n",
"2012-01-05 59.419998 59.450001 58.869999 59.000000 8069400.0 51.459220\n",
"2012-01-06 59.029999 59.549999 58.919998 59.180000 6679300.0 51.616215\n",
"2012-01-09 59.430000 59.709999 58.980000 59.040001 6907300.0 51.494109"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.shift(-1).head()"
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Volume</th>\n",
" <th>Adj Close</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2016-12-23</th>\n",
" <td>69.300003</td>\n",
" <td>69.820000</td>\n",
" <td>69.250000</td>\n",
" <td>69.699997</td>\n",
" <td>4435700.0</td>\n",
" <td>69.191240</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-27</th>\n",
" <td>69.940002</td>\n",
" <td>70.000000</td>\n",
" <td>69.260002</td>\n",
" <td>69.309998</td>\n",
" <td>4875700.0</td>\n",
" <td>68.804087</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-28</th>\n",
" <td>69.209999</td>\n",
" <td>69.519997</td>\n",
" <td>69.120003</td>\n",
" <td>69.260002</td>\n",
" <td>4298400.0</td>\n",
" <td>68.754456</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-29</th>\n",
" <td>69.120003</td>\n",
" <td>69.430000</td>\n",
" <td>68.830002</td>\n",
" <td>69.120003</td>\n",
" <td>6889500.0</td>\n",
" <td>68.615479</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2016-12-30</th>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" <td>NaN</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2016-12-23 69.300003 69.820000 69.250000 69.699997 4435700.0 69.191240\n",
"2016-12-27 69.940002 70.000000 69.260002 69.309998 4875700.0 68.804087\n",
"2016-12-28 69.209999 69.519997 69.120003 69.260002 4298400.0 68.754456\n",
"2016-12-29 69.120003 69.430000 68.830002 69.120003 6889500.0 68.615479\n",
"2016-12-30 NaN NaN NaN NaN NaN NaN"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"df.shift(-1).tail()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Shifting based off Time String Code \n",
"### Using tshift()"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>Open</th>\n",
" <th>High</th>\n",
" <th>Low</th>\n",
" <th>Close</th>\n",
" <th>Volume</th>\n",
" <th>Adj Close</th>\n",
" </tr>\n",
" <tr>\n",
" <th>Date</th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" <th></th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>2012-01-31</th>\n",
" <td>59.970001</td>\n",
" <td>61.060001</td>\n",
" <td>59.869999</td>\n",
" <td>60.330002</td>\n",
" <td>12668800</td>\n",
" <td>52.619235</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-31</th>\n",
" <td>60.209999</td>\n",
" <td>60.349998</td>\n",
" <td>59.470001</td>\n",
" <td>59.709999</td>\n",
" <td>9593300</td>\n",
" <td>52.078475</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-31</th>\n",
" <td>59.349998</td>\n",
" <td>59.619999</td>\n",
" <td>58.369999</td>\n",
" <td>59.419998</td>\n",
" <td>12768200</td>\n",
" <td>51.825539</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-31</th>\n",
" <td>59.419998</td>\n",
" <td>59.450001</td>\n",
" <td>58.869999</td>\n",
" <td>59.000000</td>\n",
" <td>8069400</td>\n",
" <td>51.459220</td>\n",
" </tr>\n",
" <tr>\n",
" <th>2012-01-31</th>\n",
" <td>59.029999</td>\n",
" <td>59.549999</td>\n",
" <td>58.919998</td>\n",
" <td>59.180000</td>\n",
" <td>6679300</td>\n",
" <td>51.616215</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2012-01-31 59.970001 61.060001 59.869999 60.330002 12668800 52.619235\n",
"2012-01-31 60.209999 60.349998 59.470001 59.709999 9593300 52.078475\n",
"2012-01-31 59.349998 59.619999 58.369999 59.419998 12768200 51.825539\n",
"2012-01-31 59.419998 59.450001 58.869999 59.000000 8069400 51.459220\n",
"2012-01-31 59.029999 59.549999 58.919998 59.180000 6679300 51.616215"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Shift everything forward one month\n",
"df.tshift(periods=1,freq='M').head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"That is it for now!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Python [conda root]",
"language": "python",
"name": "conda-root-py"
},
"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.5.3"
}
},
"nbformat": 4,
"nbformat_minor": 0
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,396 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction aux Séries temporelles avec Pandas\n",
"\n",
"Beaucoup de nos données financières auront un index datatime, alors apprenons comment traiter ce genre de données avec pandas !"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from datetime import datetime"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# pour illustrer l'ordre des arguments\n",
"my_year = 2017\n",
"my_month = 1\n",
"my_day = 2\n",
"my_hour = 13\n",
"my_minute = 30\n",
"my_second = 15"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"# January 2nd, 2017\n",
"my_date = datetime(my_year,my_month,my_day)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"datetime.datetime(2017, 1, 2, 0, 0)"
]
},
"metadata": {},
"execution_count": 5
}
],
"source": [
"# Par défaut 0:00\n",
"my_date "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"# January 2nd, 2017 à 13:30:15\n",
"my_date_time = datetime(my_year,my_month,my_day,my_hour,my_minute,my_second)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"datetime.datetime(2017, 1, 2, 13, 30, 15)"
]
},
"metadata": {},
"execution_count": 7
}
],
"source": [
"my_date_time"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Vous pouvez saisir n'importe quelle partie de l'objet datetime:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"2"
]
},
"metadata": {},
"execution_count": 8
}
],
"source": [
"my_date.day"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"13"
]
},
"metadata": {},
"execution_count": 9
}
],
"source": [
"my_date_time.hour"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Index dataetime avec Pandas\n",
"\n",
"Vous traiterez généralement les séries temporelles comme un index lorsque vous travaillez avec des dataframes pandas obtenues à partir d'APIs financières. Heureusement, pandas a beaucoup de fonctions et de méthodes pour travailler avec des séries temporelles !"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[datetime.datetime(2016, 1, 1, 0, 0), datetime.datetime(2016, 1, 2, 0, 0)]"
]
},
"metadata": {},
"execution_count": 10
}
],
"source": [
"# Créer un exemple de liste/tableau datetime\n",
"first_two = [datetime(2016, 1, 1), datetime(2016, 1, 2)]\n",
"first_two"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"DatetimeIndex(['2016-01-01', '2016-01-02'], dtype='datetime64[ns]', freq=None)"
]
},
"metadata": {},
"execution_count": 11
}
],
"source": [
"# Converti en un index\n",
"dt_ind = pd.DatetimeIndex(first_two)\n",
"dt_ind"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"[[-1.05763777 -0.15818632]\n [-0.79985649 -0.93157171]]\n"
]
}
],
"source": [
"# Quelques données alétaoires\n",
"data = np.random.randn(2,2)\n",
"print(data)\n",
"cols = ['A','B']"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"df = pd.DataFrame(data,dt_ind,cols)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" A B\n",
"2016-01-01 -1.057638 -0.158186\n",
"2016-01-02 -0.799856 -0.931572"
],
"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 </tr>\n </thead>\n <tbody>\n <tr>\n <th>2016-01-01</th>\n <td>-1.057638</td>\n <td>-0.158186</td>\n </tr>\n <tr>\n <th>2016-01-02</th>\n <td>-0.799856</td>\n <td>-0.931572</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 14
}
],
"source": [
"df"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"DatetimeIndex(['2016-01-01', '2016-01-02'], dtype='datetime64[ns]', freq=None)"
]
},
"metadata": {},
"execution_count": 15
}
],
"source": [
"df.index"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"1"
]
},
"metadata": {},
"execution_count": 16
}
],
"source": [
"# Emplacement de la date la plus récente\n",
"df.index.argmax()"
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Timestamp('2016-01-02 00:00:00')"
]
},
"metadata": {},
"execution_count": 17
}
],
"source": [
"df.index.max()"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"0"
]
},
"metadata": {},
"execution_count": 18
}
],
"source": [
"# Emplacement de la date la plus ancienne\n",
"df.index.argmin()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"Timestamp('2016-01-01 00:00:00')"
]
},
"metadata": {},
"execution_count": 19
}
],
"source": [
"df.index.min()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Top, passons à la suite!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.9 64-bit ('pyfinance': conda)",
"metadata": {
"interpreter": {
"hash": "e89404a230d8800c54ad520c7b67d1bd9bb833a07b37dd3e521a178a3dc34904"
}
}
},
"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.7.9-final"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

View File

@ -0,0 +1,281 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Décalage Temporel\n",
"\n",
"Parfois, vous pouvez avoir besoin de déplacer toutes vos données vers le haut ou vers le bas le long de l'index des séries temporelles, en fait, beaucoup de méthodes intégrées pandas le font. Ce n'est pas quelque chose que nous ferons souvent dans le cours, mais c'est très bon à connaître !"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"import matplotlib.pyplot as plt\n",
"%matplotlib inline"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"df = pd.read_csv('time_data/walmart_stock.csv',index_col='Date')\n",
"df.index = pd.to_datetime(df.index)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2012-01-03 59.970001 61.060001 59.869999 60.330002 12668800 52.619235\n",
"2012-01-04 60.209999 60.349998 59.470001 59.709999 9593300 52.078475\n",
"2012-01-05 59.349998 59.619999 58.369999 59.419998 12768200 51.825539\n",
"2012-01-06 59.419998 59.450001 58.869999 59.000000 8069400 51.459220\n",
"2012-01-09 59.029999 59.549999 58.919998 59.180000 6679300 51.616215"
],
"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>Open</th>\n <th>High</th>\n <th>Low</th>\n <th>Close</th>\n <th>Volume</th>\n <th>Adj Close</th>\n </tr>\n <tr>\n <th>Date</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2012-01-03</th>\n <td>59.970001</td>\n <td>61.060001</td>\n <td>59.869999</td>\n <td>60.330002</td>\n <td>12668800</td>\n <td>52.619235</td>\n </tr>\n <tr>\n <th>2012-01-04</th>\n <td>60.209999</td>\n <td>60.349998</td>\n <td>59.470001</td>\n <td>59.709999</td>\n <td>9593300</td>\n <td>52.078475</td>\n </tr>\n <tr>\n <th>2012-01-05</th>\n <td>59.349998</td>\n <td>59.619999</td>\n <td>58.369999</td>\n <td>59.419998</td>\n <td>12768200</td>\n <td>51.825539</td>\n </tr>\n <tr>\n <th>2012-01-06</th>\n <td>59.419998</td>\n <td>59.450001</td>\n <td>58.869999</td>\n <td>59.000000</td>\n <td>8069400</td>\n <td>51.459220</td>\n </tr>\n <tr>\n <th>2012-01-09</th>\n <td>59.029999</td>\n <td>59.549999</td>\n <td>58.919998</td>\n <td>59.180000</td>\n <td>6679300</td>\n <td>51.616215</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 3
}
],
"source": [
"df.head()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2016-12-23 69.430000 69.750000 69.360001 69.540001 4803900 69.032411\n",
"2016-12-27 69.300003 69.820000 69.250000 69.699997 4435700 69.191240\n",
"2016-12-28 69.940002 70.000000 69.260002 69.309998 4875700 68.804087\n",
"2016-12-29 69.209999 69.519997 69.120003 69.260002 4298400 68.754456\n",
"2016-12-30 69.120003 69.430000 68.830002 69.120003 6889500 68.615479"
],
"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>Open</th>\n <th>High</th>\n <th>Low</th>\n <th>Close</th>\n <th>Volume</th>\n <th>Adj Close</th>\n </tr>\n <tr>\n <th>Date</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2016-12-23</th>\n <td>69.430000</td>\n <td>69.750000</td>\n <td>69.360001</td>\n <td>69.540001</td>\n <td>4803900</td>\n <td>69.032411</td>\n </tr>\n <tr>\n <th>2016-12-27</th>\n <td>69.300003</td>\n <td>69.820000</td>\n <td>69.250000</td>\n <td>69.699997</td>\n <td>4435700</td>\n <td>69.191240</td>\n </tr>\n <tr>\n <th>2016-12-28</th>\n <td>69.940002</td>\n <td>70.000000</td>\n <td>69.260002</td>\n <td>69.309998</td>\n <td>4875700</td>\n <td>68.804087</td>\n </tr>\n <tr>\n <th>2016-12-29</th>\n <td>69.209999</td>\n <td>69.519997</td>\n <td>69.120003</td>\n <td>69.260002</td>\n <td>4298400</td>\n <td>68.754456</td>\n </tr>\n <tr>\n <th>2016-12-30</th>\n <td>69.120003</td>\n <td>69.430000</td>\n <td>68.830002</td>\n <td>69.120003</td>\n <td>6889500</td>\n <td>68.615479</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 4
}
],
"source": [
"df.tail()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## .shift() - décalage en avance"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2012-01-03 NaN NaN NaN NaN NaN NaN\n",
"2012-01-04 59.970001 61.060001 59.869999 60.330002 12668800.0 52.619235\n",
"2012-01-05 60.209999 60.349998 59.470001 59.709999 9593300.0 52.078475\n",
"2012-01-06 59.349998 59.619999 58.369999 59.419998 12768200.0 51.825539\n",
"2012-01-09 59.419998 59.450001 58.869999 59.000000 8069400.0 51.459220"
],
"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>Open</th>\n <th>High</th>\n <th>Low</th>\n <th>Close</th>\n <th>Volume</th>\n <th>Adj Close</th>\n </tr>\n <tr>\n <th>Date</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2012-01-03</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n <tr>\n <th>2012-01-04</th>\n <td>59.970001</td>\n <td>61.060001</td>\n <td>59.869999</td>\n <td>60.330002</td>\n <td>12668800.0</td>\n <td>52.619235</td>\n </tr>\n <tr>\n <th>2012-01-05</th>\n <td>60.209999</td>\n <td>60.349998</td>\n <td>59.470001</td>\n <td>59.709999</td>\n <td>9593300.0</td>\n <td>52.078475</td>\n </tr>\n <tr>\n <th>2012-01-06</th>\n <td>59.349998</td>\n <td>59.619999</td>\n <td>58.369999</td>\n <td>59.419998</td>\n <td>12768200.0</td>\n <td>51.825539</td>\n </tr>\n <tr>\n <th>2012-01-09</th>\n <td>59.419998</td>\n <td>59.450001</td>\n <td>58.869999</td>\n <td>59.000000</td>\n <td>8069400.0</td>\n <td>51.459220</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 5
}
],
"source": [
"df.shift(1).head()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2016-12-23 71.239998 71.239998 69.209999 69.589996 12106800.0 69.082042\n",
"2016-12-27 69.430000 69.750000 69.360001 69.540001 4803900.0 69.032411\n",
"2016-12-28 69.300003 69.820000 69.250000 69.699997 4435700.0 69.191240\n",
"2016-12-29 69.940002 70.000000 69.260002 69.309998 4875700.0 68.804087\n",
"2016-12-30 69.209999 69.519997 69.120003 69.260002 4298400.0 68.754456"
],
"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>Open</th>\n <th>High</th>\n <th>Low</th>\n <th>Close</th>\n <th>Volume</th>\n <th>Adj Close</th>\n </tr>\n <tr>\n <th>Date</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2016-12-23</th>\n <td>71.239998</td>\n <td>71.239998</td>\n <td>69.209999</td>\n <td>69.589996</td>\n <td>12106800.0</td>\n <td>69.082042</td>\n </tr>\n <tr>\n <th>2016-12-27</th>\n <td>69.430000</td>\n <td>69.750000</td>\n <td>69.360001</td>\n <td>69.540001</td>\n <td>4803900.0</td>\n <td>69.032411</td>\n </tr>\n <tr>\n <th>2016-12-28</th>\n <td>69.300003</td>\n <td>69.820000</td>\n <td>69.250000</td>\n <td>69.699997</td>\n <td>4435700.0</td>\n <td>69.191240</td>\n </tr>\n <tr>\n <th>2016-12-29</th>\n <td>69.940002</td>\n <td>70.000000</td>\n <td>69.260002</td>\n <td>69.309998</td>\n <td>4875700.0</td>\n <td>68.804087</td>\n </tr>\n <tr>\n <th>2016-12-30</th>\n <td>69.209999</td>\n <td>69.519997</td>\n <td>69.120003</td>\n <td>69.260002</td>\n <td>4298400.0</td>\n <td>68.754456</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 6
}
],
"source": [
"# You will lose that last piece of data that no longer has an index!\n",
"df.shift(1).tail()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## shift() - décalage en arrière"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2012-01-03 60.209999 60.349998 59.470001 59.709999 9593300.0 52.078475\n",
"2012-01-04 59.349998 59.619999 58.369999 59.419998 12768200.0 51.825539\n",
"2012-01-05 59.419998 59.450001 58.869999 59.000000 8069400.0 51.459220\n",
"2012-01-06 59.029999 59.549999 58.919998 59.180000 6679300.0 51.616215\n",
"2012-01-09 59.430000 59.709999 58.980000 59.040001 6907300.0 51.494109"
],
"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>Open</th>\n <th>High</th>\n <th>Low</th>\n <th>Close</th>\n <th>Volume</th>\n <th>Adj Close</th>\n </tr>\n <tr>\n <th>Date</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2012-01-03</th>\n <td>60.209999</td>\n <td>60.349998</td>\n <td>59.470001</td>\n <td>59.709999</td>\n <td>9593300.0</td>\n <td>52.078475</td>\n </tr>\n <tr>\n <th>2012-01-04</th>\n <td>59.349998</td>\n <td>59.619999</td>\n <td>58.369999</td>\n <td>59.419998</td>\n <td>12768200.0</td>\n <td>51.825539</td>\n </tr>\n <tr>\n <th>2012-01-05</th>\n <td>59.419998</td>\n <td>59.450001</td>\n <td>58.869999</td>\n <td>59.000000</td>\n <td>8069400.0</td>\n <td>51.459220</td>\n </tr>\n <tr>\n <th>2012-01-06</th>\n <td>59.029999</td>\n <td>59.549999</td>\n <td>58.919998</td>\n <td>59.180000</td>\n <td>6679300.0</td>\n <td>51.616215</td>\n </tr>\n <tr>\n <th>2012-01-09</th>\n <td>59.430000</td>\n <td>59.709999</td>\n <td>58.980000</td>\n <td>59.040001</td>\n <td>6907300.0</td>\n <td>51.494109</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 7
}
],
"source": [
"df.shift(-1).head()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2016-12-23 69.300003 69.820000 69.250000 69.699997 4435700.0 69.191240\n",
"2016-12-27 69.940002 70.000000 69.260002 69.309998 4875700.0 68.804087\n",
"2016-12-28 69.209999 69.519997 69.120003 69.260002 4298400.0 68.754456\n",
"2016-12-29 69.120003 69.430000 68.830002 69.120003 6889500.0 68.615479\n",
"2016-12-30 NaN NaN NaN NaN NaN NaN"
],
"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>Open</th>\n <th>High</th>\n <th>Low</th>\n <th>Close</th>\n <th>Volume</th>\n <th>Adj Close</th>\n </tr>\n <tr>\n <th>Date</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2016-12-23</th>\n <td>69.300003</td>\n <td>69.820000</td>\n <td>69.250000</td>\n <td>69.699997</td>\n <td>4435700.0</td>\n <td>69.191240</td>\n </tr>\n <tr>\n <th>2016-12-27</th>\n <td>69.940002</td>\n <td>70.000000</td>\n <td>69.260002</td>\n <td>69.309998</td>\n <td>4875700.0</td>\n <td>68.804087</td>\n </tr>\n <tr>\n <th>2016-12-28</th>\n <td>69.209999</td>\n <td>69.519997</td>\n <td>69.120003</td>\n <td>69.260002</td>\n <td>4298400.0</td>\n <td>68.754456</td>\n </tr>\n <tr>\n <th>2016-12-29</th>\n <td>69.120003</td>\n <td>69.430000</td>\n <td>68.830002</td>\n <td>69.120003</td>\n <td>6889500.0</td>\n <td>68.615479</td>\n </tr>\n <tr>\n <th>2016-12-30</th>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n <td>NaN</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 8
}
],
"source": [
"df.shift(-1).tail()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Décalage basé sur le Code Time String\n",
"### Utilisation de tshift()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
" Open High Low Close Volume Adj Close\n",
"Date \n",
"2012-01-31 59.970001 61.060001 59.869999 60.330002 12668800 52.619235\n",
"2012-01-31 60.209999 60.349998 59.470001 59.709999 9593300 52.078475\n",
"2012-01-31 59.349998 59.619999 58.369999 59.419998 12768200 51.825539\n",
"2012-01-31 59.419998 59.450001 58.869999 59.000000 8069400 51.459220\n",
"2012-01-31 59.029999 59.549999 58.919998 59.180000 6679300 51.616215"
],
"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>Open</th>\n <th>High</th>\n <th>Low</th>\n <th>Close</th>\n <th>Volume</th>\n <th>Adj Close</th>\n </tr>\n <tr>\n <th>Date</th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n <th></th>\n </tr>\n </thead>\n <tbody>\n <tr>\n <th>2012-01-31</th>\n <td>59.970001</td>\n <td>61.060001</td>\n <td>59.869999</td>\n <td>60.330002</td>\n <td>12668800</td>\n <td>52.619235</td>\n </tr>\n <tr>\n <th>2012-01-31</th>\n <td>60.209999</td>\n <td>60.349998</td>\n <td>59.470001</td>\n <td>59.709999</td>\n <td>9593300</td>\n <td>52.078475</td>\n </tr>\n <tr>\n <th>2012-01-31</th>\n <td>59.349998</td>\n <td>59.619999</td>\n <td>58.369999</td>\n <td>59.419998</td>\n <td>12768200</td>\n <td>51.825539</td>\n </tr>\n <tr>\n <th>2012-01-31</th>\n <td>59.419998</td>\n <td>59.450001</td>\n <td>58.869999</td>\n <td>59.000000</td>\n <td>8069400</td>\n <td>51.459220</td>\n </tr>\n <tr>\n <th>2012-01-31</th>\n <td>59.029999</td>\n <td>59.549999</td>\n <td>58.919998</td>\n <td>59.180000</td>\n <td>6679300</td>\n <td>51.616215</td>\n </tr>\n </tbody>\n</table>\n</div>"
},
"metadata": {},
"execution_count": 9
}
],
"source": [
"# Avancer tout d'un mois\n",
"df.tshift(periods=1,freq='M').head()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"C'est tout pour maintenant!"
]
}
],
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"name": "python3",
"display_name": "Python 3.7.9 64-bit ('pyfinance': conda)",
"metadata": {
"interpreter": {
"hash": "e89404a230d8800c54ad520c7b67d1bd9bb833a07b37dd3e521a178a3dc34904"
}
}
},
"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.7.9-final"
}
},
"nbformat": 4,
"nbformat_minor": 1
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,148 @@
"Month","Thousands of Passengers"
"1949-01",112
"1949-02",118
"1949-03",132
"1949-04",129
"1949-05",121
"1949-06",135
"1949-07",148
"1949-08",148
"1949-09",136
"1949-10",119
"1949-11",104
"1949-12",118
"1950-01",115
"1950-02",126
"1950-03",141
"1950-04",135
"1950-05",125
"1950-06",149
"1950-07",170
"1950-08",170
"1950-09",158
"1950-10",133
"1950-11",114
"1950-12",140
"1951-01",145
"1951-02",150
"1951-03",178
"1951-04",163
"1951-05",172
"1951-06",178
"1951-07",199
"1951-08",199
"1951-09",184
"1951-10",162
"1951-11",146
"1951-12",166
"1952-01",171
"1952-02",180
"1952-03",193
"1952-04",181
"1952-05",183
"1952-06",218
"1952-07",230
"1952-08",242
"1952-09",209
"1952-10",191
"1952-11",172
"1952-12",194
"1953-01",196
"1953-02",196
"1953-03",236
"1953-04",235
"1953-05",229
"1953-06",243
"1953-07",264
"1953-08",272
"1953-09",237
"1953-10",211
"1953-11",180
"1953-12",201
"1954-01",204
"1954-02",188
"1954-03",235
"1954-04",227
"1954-05",234
"1954-06",264
"1954-07",302
"1954-08",293
"1954-09",259
"1954-10",229
"1954-11",203
"1954-12",229
"1955-01",242
"1955-02",233
"1955-03",267
"1955-04",269
"1955-05",270
"1955-06",315
"1955-07",364
"1955-08",347
"1955-09",312
"1955-10",274
"1955-11",237
"1955-12",278
"1956-01",284
"1956-02",277
"1956-03",317
"1956-04",313
"1956-05",318
"1956-06",374
"1956-07",413
"1956-08",405
"1956-09",355
"1956-10",306
"1956-11",271
"1956-12",306
"1957-01",315
"1957-02",301
"1957-03",356
"1957-04",348
"1957-05",355
"1957-06",422
"1957-07",465
"1957-08",467
"1957-09",404
"1957-10",347
"1957-11",305
"1957-12",336
"1958-01",340
"1958-02",318
"1958-03",362
"1958-04",348
"1958-05",363
"1958-06",435
"1958-07",491
"1958-08",505
"1958-09",404
"1958-10",359
"1958-11",310
"1958-12",337
"1959-01",360
"1959-02",342
"1959-03",406
"1959-04",396
"1959-05",420
"1959-06",472
"1959-07",548
"1959-08",559
"1959-09",463
"1959-10",407
"1959-11",362
"1959-12",405
"1960-01",417
"1960-02",391
"1960-03",419
"1960-04",461
"1960-05",472
"1960-06",535
"1960-07",622
"1960-08",606
"1960-09",508
"1960-10",461
"1960-11",390
"1960-12",432
International airline passengers: monthly totals in thousands. Jan 49 ? Dec 60
Can't render this file because it has a wrong number of fields in line 147.

View File

@ -0,0 +1,172 @@
"Month","Monthly milk production: pounds per cow. Jan 62 ? Dec 75"
"1962-01",589
"1962-02",561
"1962-03",640
"1962-04",656
"1962-05",727
"1962-06",697
"1962-07",640
"1962-08",599
"1962-09",568
"1962-10",577
"1962-11",553
"1962-12",582
"1963-01",600
"1963-02",566
"1963-03",653
"1963-04",673
"1963-05",742
"1963-06",716
"1963-07",660
"1963-08",617
"1963-09",583
"1963-10",587
"1963-11",565
"1963-12",598
"1964-01",628
"1964-02",618
"1964-03",688
"1964-04",705
"1964-05",770
"1964-06",736
"1964-07",678
"1964-08",639
"1964-09",604
"1964-10",611
"1964-11",594
"1964-12",634
"1965-01",658
"1965-02",622
"1965-03",709
"1965-04",722
"1965-05",782
"1965-06",756
"1965-07",702
"1965-08",653
"1965-09",615
"1965-10",621
"1965-11",602
"1965-12",635
"1966-01",677
"1966-02",635
"1966-03",736
"1966-04",755
"1966-05",811
"1966-06",798
"1966-07",735
"1966-08",697
"1966-09",661
"1966-10",667
"1966-11",645
"1966-12",688
"1967-01",713
"1967-02",667
"1967-03",762
"1967-04",784
"1967-05",837
"1967-06",817
"1967-07",767
"1967-08",722
"1967-09",681
"1967-10",687
"1967-11",660
"1967-12",698
"1968-01",717
"1968-02",696
"1968-03",775
"1968-04",796
"1968-05",858
"1968-06",826
"1968-07",783
"1968-08",740
"1968-09",701
"1968-10",706
"1968-11",677
"1968-12",711
"1969-01",734
"1969-02",690
"1969-03",785
"1969-04",805
"1969-05",871
"1969-06",845
"1969-07",801
"1969-08",764
"1969-09",725
"1969-10",723
"1969-11",690
"1969-12",734
"1970-01",750
"1970-02",707
"1970-03",807
"1970-04",824
"1970-05",886
"1970-06",859
"1970-07",819
"1970-08",783
"1970-09",740
"1970-10",747
"1970-11",711
"1970-12",751
"1971-01",804
"1971-02",756
"1971-03",860
"1971-04",878
"1971-05",942
"1971-06",913
"1971-07",869
"1971-08",834
"1971-09",790
"1971-10",800
"1971-11",763
"1971-12",800
"1972-01",826
"1972-02",799
"1972-03",890
"1972-04",900
"1972-05",961
"1972-06",935
"1972-07",894
"1972-08",855
"1972-09",809
"1972-10",810
"1972-11",766
"1972-12",805
"1973-01",821
"1973-02",773
"1973-03",883
"1973-04",898
"1973-05",957
"1973-06",924
"1973-07",881
"1973-08",837
"1973-09",784
"1973-10",791
"1973-11",760
"1973-12",802
"1974-01",828
"1974-02",778
"1974-03",889
"1974-04",902
"1974-05",969
"1974-06",947
"1974-07",908
"1974-08",867
"1974-09",815
"1974-10",812
"1974-11",773
"1974-12",813
"1975-01",834
"1975-02",782
"1975-03",892
"1975-04",903
"1975-05",966
"1975-06",937
"1975-07",896
"1975-08",858
"1975-09",817
"1975-10",827
"1975-11",797
"1975-12",843
Monthly milk production: pounds per cow. Jan 62 ? Dec 75
Can't render this file because it has a wrong number of fields in line 171.

File diff suppressed because one or more lines are too long

Some files were not shown because too many files have changed in this diff Show More