teaching:progappchim:pandas

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentes Révision précédente
Prochaine révision
Révision précédente
teaching:progappchim:pandas [2019/03/11 07:28] villersdteaching:progappchim:pandas [2022/11/15 10:08] (Version actuelle) – [Références] villersd
Ligne 12: Ligne 12:
   * [[http://pandas.pydata.org/pandas-docs/version/0.20/cookbook.html|cookbook]]   * [[http://pandas.pydata.org/pandas-docs/version/0.20/cookbook.html|cookbook]]
   * [[http://pandas.pydata.org/pandas-docs/stable/user_guide/visualization.html|Visualisation]]   * [[http://pandas.pydata.org/pandas-docs/stable/user_guide/visualization.html|Visualisation]]
 +  * [[https://www.datacamp.com/community/blog/python-pandas-cheat-sheet|Pandas Cheat Sheet for Data Science in Python]]
  
 ===== Applications, exemples ===== ===== Applications, exemples =====
 +
 +==== Préambule : variable aléatoire et distributions ====
 +
 +De nombreuses grandeurs mesurées suivent une loi de distribution normale pour leur probabilité : //cf.// [[wp>fr:Loi_normale|Loi normale]]
 +
 +Voir aussi les documents de statistique élémentaire (niveau licence, France) sur le site [[http://wikistat.fr/|wikistat.fr]]
 +
 +  * **Variable aléatoire** : une variable aléatoire $X$ est définie sur l'espace des observables (espace des événements possibles). À chaque valeur possible $x$ correspond une probabilité $P(x)$ que $X$ soit égale à $x$
 +    * Variable aléatoire discrète : si $x_1, x_2, x_3, ...$ constitue l'ensemble discret des valeurs possibles de $X$, les $P(x_i)$ forment la **distribution de probabilité** de la variable aléatoire $X$
 +    * Variable aléatoire continue : si $x$ peut varier continûment, $P(x)$ est la densité de probabilité que la variable prenne une valeur comprise entre $x$ et $x+dx$. L'unité de $P(x)$ est donc en inverse de celle de l'espace des $x$ et seul $P(x) dx$ a la dimension d'une probabilité (nombre)  : $P(x) dx = P(x \le X < x+dx)$
 +    * Positivité :
 +      * $P(x_i) \ge 0$ pour tout $x_i$ (variable aléatoire discrète)
 +      * $P(x) \ge 0$ pour tout $x$ (variable aléatoire continue)
 +    * Normalisation :
 +      * $\sum_{x_i} P(x_i) =1$ (variable aléatoire discrète)
 +      * $\int_{\Omega} P(x) dx = 1$ (variable aléatoire continue)
 +  * Toute l'information sur une expérience est contenue dans la distribution $P(x)$}
 +  * Une description **équivalente** est donnée par l'ensemble de toutes les grandeurs caractéristiques appelées {\bf moments de la distribution} :
 +    * $<X^n> = \sum_i x_i^n P(x_i)$ (variable aléatoire discrète, avec n fini)
 +    * $<X^n> = \int_{\Omega} x^n P(x) dx$ (variable aléatoire continue, avec n infini)
 +  * Une description **simplifiée** est obtenue en ne tenant compte que de quelques plus petites valeurs de n :
 +    * Premier moment: moyenne $<X>$ (ou [[http://fr.wikipedia.org/wiki/Esp%C3%A9rance_math%C3%A9matique|espérance mathématique]])
 +    * Second moment: largeur de la distribution ([[http://fr.wikipedia.org/wiki/Variance_%28statistiques_et_probabilit%C3%A9s%29|variance]] $\sigma^2$)
 +    * Troisième moment : asymétrie ([[http://fr.wikipedia.org/wiki/Skewness|skewness]])
 +    * Quatrième moment : aplatissement ([[http://fr.wikipedia.org/wiki/Kurtosis|kurtosis]])
 +    * ...
 +  * Les deux premiers moments
 +    * **Valeur moyenne ou espérance**
 +      * $<X> = \sum_i x_i \ P(x_i)$ ou $<X> = \int_{{\Omega}} x \ P(x) dx$ avec ${\Omega}$ le volume de l'espace des phases/observables
 +    * **Variance**
 +      * La variance $Var(X)$ ou $\sigma^2$ caractérise la largeur de la distribution (ou l'écart à la moyenne) : $\sigma^2 = <(X - <X>)^2> = <X^2> - <X>^2$. La racine carrée est l'écart type, $\sigma$.
  
 ==== Statistiques sur les dimensions des humains (body dimensions) ==== ==== Statistiques sur les dimensions des humains (body dimensions) ====
 +
 Programme basé sur [[http://jse.amstat.org/v11n2/datasets.heinz.html|Exploring Relationships in Body Dimensions]]. Programme basé sur [[http://jse.amstat.org/v11n2/datasets.heinz.html|Exploring Relationships in Body Dimensions]].
  
 Extensions : Extensions :
-  * Tester et utiliser en mode "Jupyter"+  * Tester et utiliser en mode [[jupyter|"Jupyter"]] 
 +    * si vous n'y arrivez pas, vous pouvez utiliser ce fichier : {{:teaching:progappchim:body_dimensions_01.ipynb}}
   * créer des régressions   * créer des régressions
   * autres représentations   * autres représentations
   * différentiation suivant le genre, l'âge   * différentiation suivant le genre, l'âge
 +  * utiliser d'autres fonctions, comme nsmallest() et nlargest(), value_counts() (se baser sur la documentation officielle)
   * ...   * ...
  
Ligne 75: Ligne 110:
 namesfr = [ namesfr = [
     'Largeur des épaules',     'Largeur des épaules',
-    'Largueur des hanches', +    'Largeur des hanches', 
-    'Largueur entre têtes de fémur', +    'Largeur entre têtes de fémur', 
-    'Epaisseur du thorax',  +    'Epaisseur du thorax', 
-    'Largueur du thorax',  +    'Largeur du thorax', 
-    'Largueur du coude',  +    'Largeur du coude', 
-    'Largueur du poignet',  +    'Largeur du poignet', 
-    'Largueur du genou',  +    'Largeur du genou', 
-    'Largueur de la cheville',  +    'Largeur de la cheville', 
-    'Tour d’épaules',  +    'Tour d’épaules', 
-    'Tour de poitrine',  +    'Tour de poitrine', 
-    'Tour de taille',  +    'Tour de taille', 
-    'Tour au niveau du nombril',  +    'Tour au niveau du nombril', 
-    'Tour de hanches',  +    'Tour de hanches', 
-    'Tour de cuisse',  +    'Tour de cuisse', 
-    'Tour du biceps', +    'Tour du biceps', 
-    'Tour de l’avant-bras', +    'Tour de l’avant-bras', 
-    'Tour de genou', +    'Tour de genou', 
-    'Plus grande circonférence du mollet', +    'Plus grande circonférence du mollet', 
-    'Plus petite circonférence de la cheville', +    'Plus petite circonférence de la cheville', 
-    'Plus petite circonférence du poignet', +    'Plus petite circonférence du poignet', 
-    'Âge', +    'Âge', 
-    'Poids', +    'Poids', 
-    'Taille', +    'Taille', 
-    'Genre',+    'Genre',
     ]     ]
  
Ligne 137: Ligne 172:
 plt.figure() plt.figure()
 df.Weight.plot.hist() df.Weight.plot.hist()
 +
 +plt.show()
 </code> </code>
 +
 +=== Suggestions pour ajouter une régression linéaire ===
 +FIXME
 +  * librairie scipy, fonction stats.linregress
 +
 +Codes (à combiner...)
 +
 +<code python>
 +import pandas as pd
 +from scipy import stats
 +</code>
 +
 +Références :
 +  * [[https://www.delftstack.com/api/scipy/scipy-scipy.stats.linregress-method/|SciPy scipy.stats.linregress Method]]
 +  * [[https://medium.com/analytics-vidhya/linear-regression-in-python-from-scratch-with-scipy-statsmodels-sklearn-da8e373cc89b|Linear Regression in python from scratch with scipy, statsmodels, sklearn]]
 +  * [[https://towardsdatascience.com/adding-regression-lines-to-pandas-plots-with-scipy-2e23fd524adb|Adding Regression Lines to Pandas Plots with SciPy]] (yc Jupyter notebook sur GitHub)
 +  * cf. [[matplotlib_simple]]
 +  * [[https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.sort_values.html|pandas.DataFrame.sort_values]] (documentation pandas.pydata.org)
 +
 +===== Interface utilisateur graphique =====
 +  * [[https://github.com/adamerose/pandasgui|PandasGUI]]
 +    * [[https://towardsdatascience.com/pandasgui-analyzing-pandas-dataframes-with-a-graphical-user-interface-36f5c1357b1d|PandasGUI: Analyzing Pandas dataframes with a Graphical User Interface - Accessing Pandas Dataframes with a simple click of the mouse]] Parul Pandey, Medium, 24/10/2020
 +  * [[https://github.com/tkrabel/bamboolib|bamboolib]] (closed source - non libre)
  
 ===== Références ===== ===== Références =====
   * [[https://www.tutorialspoint.com/python_pandas/index.htm]]   * [[https://www.tutorialspoint.com/python_pandas/index.htm]]
 +  * [[https://towardsdatascience.com/top-4-repositories-on-github-to-learn-pandas-1008cb769f77|Top 4 Repositories on GitHub to Learn Pandas - Some of the most popular repositories to brush up on Pandas for beginners and experts alike]] Byron Dolon, Medium, Jul 21, 2020
 +    * [[https://github.com/guipsamora/pandas_exercises|GitHub - guipsamora/pandas_exercises: Practice your pandas skills!]]
 +    * [[https://github.com/justmarkham/pandas-videos|GitHub - justmarkham/pandas-videos: Jupyter notebook and datasets from the pandas Q&A video series]]
 +    * [[https://github.com/ajcr/100-pandas-puzzles|GitHub - ajcr/100-pandas-puzzles: 100 data puzzles for pandas, ranging from short and simple to super tricky (60% complete)]]
 +    * [[https://github.com/justmarkham/pycon-2019-tutorial|GitHub - justmarkham/pycon-2019-tutorial: Data Science Best Practices with pandas]]
   * [[https://medium.com/@devopslearning/introduction-to-pandas-for-data-analysis-c14bb9b1c21b]] (limité)   * [[https://medium.com/@devopslearning/introduction-to-pandas-for-data-analysis-c14bb9b1c21b]] (limité)
   * [[http://www.firstpythonnotebook.org/index.html|First Python Notebook. A step-by-step guide to analyzing data with Python and the Jupyter Notebook]] (The course will teach you how to use pandas to read, filter, join, group, aggregate and rank structured data. You will also learn how to record, remix and republish your analysis using the Jupyter Notebook) → commencer au chapitre 3 "Import pandas into a Jupyter Notebook"   * [[http://www.firstpythonnotebook.org/index.html|First Python Notebook. A step-by-step guide to analyzing data with Python and the Jupyter Notebook]] (The course will teach you how to use pandas to read, filter, join, group, aggregate and rank structured data. You will also learn how to record, remix and republish your analysis using the Jupyter Notebook) → commencer au chapitre 3 "Import pandas into a Jupyter Notebook"
   * [[https://mubaris.com/2017-09-25/python-data-analysis-with-pandas|Python Data Analysis with pandas]]   * [[https://mubaris.com/2017-09-25/python-data-analysis-with-pandas|Python Data Analysis with pandas]]
   * [[https://www.edureka.co/blog/python-pandas-tutorial/|Python Pandas Tutorial : Learn Pandas for Data Analysis]]   * [[https://www.edureka.co/blog/python-pandas-tutorial/|Python Pandas Tutorial : Learn Pandas for Data Analysis]]
 +  * [[https://medium.com/dunder-data/minimally-sufficient-pandas-a8e67f2a2428|Minimally Sufficient Pandas]]
 +    * //cf.// aussi [[https://github.com/tdpetrou/Master-Data-Analysis-with-Python|Master Data Analysis with Python]] et les données disponibles comme exemples
   * [[https://towardsdatascience.com/python-for-data-science-8-concepts-you-may-have-forgotten-i-did-825966908393|Python for Data Science: 8 Concepts You May Have Forgotten]]   * [[https://towardsdatascience.com/python-for-data-science-8-concepts-you-may-have-forgotten-i-did-825966908393|Python for Data Science: 8 Concepts You May Have Forgotten]]
   * [[https://towardsdatascience.com/23-great-pandas-codes-for-data-scientists-cca5ed9d8a38|23 great Pandas codes for Data Scientists]]   * [[https://towardsdatascience.com/23-great-pandas-codes-for-data-scientists-cca5ed9d8a38|23 great Pandas codes for Data Scientists]]
Ligne 153: Ligne 220:
   * [[http://cmdlinetips.com/2018/03/how-to-make-boxplots-in-python-with-pandas-and-seaborn/|How to Make Boxplots in Python with Pandas and Seaborn?]] (and Gapminder dataset)   * [[http://cmdlinetips.com/2018/03/how-to-make-boxplots-in-python-with-pandas-and-seaborn/|How to Make Boxplots in Python with Pandas and Seaborn?]] (and Gapminder dataset)
   * [[https://www.geeksforgeeks.org/box-plot-visualization-with-pandas-and-seaborn/|Box plot visualization with Pandas and Seaborn]]   * [[https://www.geeksforgeeks.org/box-plot-visualization-with-pandas-and-seaborn/|Box plot visualization with Pandas and Seaborn]]
 +  * [[https://towardsdatascience.com/complete-guide-to-data-visualization-with-python-2dd74df12b5e|Complete Guide to Data Visualization with Python]] (avec différentes librairies : matplotlib, Seaborn, bokeh, Altair, Folium avec des cartes,...)
 +  * [[https://towardsdatascience.com/introducing-bamboolib-a-gui-for-pandas-4f6c091089e3|Introducing Bamboolib — a GUI for Pandas]] (utilisation gratuite ou payante via une activation nécessaire dans jupyter)
 +    * [[https://bamboolib.8080labs.com/]]
 +    * [[https://github.com/tkrabel/bamboolib]]
 +  * [[https://towardsdatascience.com/violin-plot-its-time-to-ditch-the-box-plots-785629b0ff3a|Violin Plot — It’s Time to Ditch the Box Plots]]
 +  * [[https://towardsdatascience.com/reshape-pandas-dataframe-with-melt-in-python-tutorial-and-visualization-29ec1450bb02|Reshape pandas dataframe with melt in Python — tutorial and visualization]]
 +    * [[https://pandas.pydata.org/docs/reference/api/pandas.melt.html|pandas.melt]] (documentation)
 +  * groupby :
 +    * [[https://towardsdatascience.com/learn-how-to-master-groupby-function-in-python-now-4620dd463224|Learn how to master groupby function in Python now | by WY Fok | Towards Data Science]]
 +    * [[https://towardsdatascience.com/less-known-pandas-groupby-applications-in-python-72fb304a1973|Less known Pandas groupby applications in Python | by WY Fok | Aug, 2020 | Towards Data Science]]
 +  * remplacer Excel (ou calc de libreoffice)
 +    * [[https://towardsdatascience.com/how-to-ditch-excel-a-primer-to-python-c4a9c192e993|Ditch Excel! — A Primer to Python - Pandas one-liners for popular excel stuff]], Medium 01/09/2020
 +  * [[https://towardsdatascience.com/how-not-to-write-pandas-code-2cbda8b3816c|How NOT to write pandas code]]
 +  * [[https://towardsdatascience.com/40-examples-to-master-pandas-c69d058f434e|40 Examples to Master Pandas - A comprehensive practical guide]]
 +  * [[https://towardsdatascience.com/pandas-fundamentals-for-beginners-that-will-help-you-code-like-a-pro-2ff5e34fee09|Pandas fundamentals every data scientist needs to know - To boost your performance and code like a pro]] Mısra Turp, Medium, 07/01/2021
 +  * [[https://python.plainenglish.io/add-some-style-to-your-pandas-dataframe-ae3ed4ac7804|Add Some Style to your Pandas DataFrame - Putting Some Pizzaz into your Data]] Curt Beck; Medium, Oct 11, 2020
 +  * [[https://towardsdatascience.com/spreadsheets-to-python-its-time-to-make-the-switch-ef49cf9463d5|Spreadsheets to Python: it's time]]  Clive Siviour, Towards Data Science, Medium 03/09/2021
 +  * [[https://towardsdatascience.com/efficiently-iterating-over-rows-in-a-pandas-dataframe-7dd5f9992c01|Efficiently iterating over rows in a Pandas DataFrame - Never use iterrows and itertuples again]] Maxime Labonne, Towards Data Science (Medium), 21/03/2022 → l'approche pythonique "list comprehension" fait gagner un facteur énorme par rapport aux codes utilisant les boucles (certaines techniques sont carrément désastreuses), alors que ce n'est pas le cas avec des langages compilés comme C ou Fortran. Pandas étant construit au dessus de NumPy, il n'est  pas étonnant que ses performances peuvent être dépassés par celles de Numpy dans certains cas (x1900 plutôt que x1500 dans cet article par rapport à la plus mauvaise solution).
 +  * [[https://towardsdatascience.com/pandas-df-to-numpy-array-c1a9e7d8585f|How To Convert Pandas DataFrame Into NumPy Array - Converting a pandas DataFrame into a NumPy array]] Giorgos Myrianthous, Medium, 06/05/2022
 +  * [[https://towardsdatascience.com/20-of-pandas-functions-that-data-scientists-use-80-of-the-time-a4ff1b694707|20% of Pandas Functions that Data Scientists Use 80% of the Time - Putting Pareto’s Principle to work on the Pandas library]] Avi Chawla, Medium, 16/05/2022
 +    - Reading a CSV file
 +    - Saving a DataFrame to a CSV file
 +    - Creating a DataFrame from a list of lists
 +    - Creating a DataFrame from a dictionary
 +    - Merging DataFrames
 +    - Sorting a DataFrame
 +    - Concatenating DataFrames
 +    - Rename column name
 +    - Add New Column
 +    - Filter DataFrame based on condition
 +    - Drop Column(s)
 +    - GroupBy
 +    - Unique Values in a column
 +    - Fill NaN values
 +    - Apply Function on a column
 +    - Remove Duplicates
 +    - Value Counts
 +    - Size of a DataFrame
 +  * [[https://towardsdatascience.com/powerful-one-liners-in-pandas-every-data-scientist-should-know-737e721b81b6|Powerful One-liners in Pandas Every Data Scientist Should Know - Things you can do in one line using Pandas]] Avi Chawla, Medium, 12/07/2022
 +  * [[https://medium.com/@shouke.wei/how-to-read-dataset-from-google-drive-with-python-pandas-64bc07bbe35|How to Read Dataset from Google Drive with Python Pandas - Easy and convenient Method to read a dataset from the Google Drive]] Shouke Wei, Medium, 11/11/2022
 + 
  
 +
 +==== Datasets ====
 +  * [[https://archive.ics.uci.edu/ml/datasets/Adult|Adult Data Set]] Predict whether income exceeds $50K/yr based on census data. Also known as "Census Income" dataset
 +  * [[https://archive.ics.uci.edu/ml/datasets.php]]
 +  * [[https://towardsdatascience.com/7-examples-to-master-line-plots-with-python-seaborn-42d8aaa383a9|7 Examples to Master Line Plots With Python Seaborn - Practical data visualization guide]] Soner Yıldırım, 12/09/2021 → Seaborn + Pandas + librairie [[https://pandas-datareader.readthedocs.io/en/latest/|pandas datareader]] donnant accès à de nombreuses données (bourses, OECD, Eurostat,...)
  
  
Ligne 162: Ligne 275:
   * régressions linéaires :   * régressions linéaires :
     * [[http://www.xavierdupre.fr/app/ensae_teaching_cs/helpsphinx/notebooks/td2a_eco_regressions_lineaires.html]]     * [[http://www.xavierdupre.fr/app/ensae_teaching_cs/helpsphinx/notebooks/td2a_eco_regressions_lineaires.html]]
 +  * [[https://towardsdatascience.com/effectively-visualize-data-across-time-to-tell-better-stories-2a2c276e031e|Effectively visualize data across time to tell better stories]] (Pandas & Plotly)
 +  * [[https://medium.com/analytics-vidhya/statistical-analysis-in-python-using-pandas-27c6a4209de2|Statistical Analysis in Python using Pandas]] Tanvi Penumudy, Medium, dec 31, 2020
 +  * [[https://towardsdatascience.com/an-ultimate-cheat-sheet-for-data-visualization-in-pandas-f7bc239c9937|An Ultimate Cheat Sheet for Data Visualization in Pandas - All the Basic Types of Visualization That Is Available in Pandas and Some Advanced Visualization That Are Extremely Useful and Time Savers]] Rashida Nasrin Sucky, Medium, 15/02/2021 (dataset, jupyter)
 +
 +
  
  • teaching/progappchim/pandas.1552285723.txt.gz
  • Dernière modification : 2019/03/11 07:28
  • de villersd