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
Prochaine révisionLes deux révisions suivantes
teaching:progappchim:pandas [2019/03/11 01:01] villersdteaching:progappchim:pandas [2019/03/11 07:28] 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]]
 +
 +===== Applications, exemples =====
 +
 +==== Statistiques sur les dimensions des humains (body dimensions) ====
 +Programme basé sur [[http://jse.amstat.org/v11n2/datasets.heinz.html|Exploring Relationships in Body Dimensions]].
 +
 +Extensions :
 +  * Tester et utiliser en mode "Jupyter"
 +  * créer des régressions
 +  * autres représentations
 +  * différentiation suivant le genre, l'âge
 +  * ...
 +
 +<code python jse-dataset-body-dimensions-read-10.py>
 +#!/usr/bin/env python3
 +# -*- coding: utf-8 -*-
 +"""
 +Created on Tue Mar  5 04:13:51 2019
 +Statistics on Body dimensions :
 +http://jse.amstat.org/v11n2/datasets.heinz.html
 +
 +without requests lib, using pandas.read_csv
 +
 +@author: Didier Villers
 +"""
 +import matplotlib.pyplot as plt
 +import numpy as np
 +import pandas as pd
 +
 +# using this VARIABLE DESCRIPTIONS with PEP 8 Python style :
 +names = [
 +    'Biacromial diameter',
 +    'Biiliac diameter',
 +    'Bitrochanteric diameter',
 +    'Chest depth',
 +    'Chest diameter',
 +    'Elbow diameter',
 +    'Wrist diameter',
 +    'Knee diameter',
 +    'Ankle diameter',
 +    'Shoulder girth',
 +    'Chest girth',
 +    'Waist girth',
 +    'Navel girth',
 +    'Hip girth',
 +    'Thigh girth',
 +    'Bicep girth',
 +    'Forearm girth',
 +    'Knee girth',
 +    'Calf maximum girth',
 +    'Ankle minimum girth',
 +    'Wrist minimum girth',
 +    'Age',
 +    'Weight',
 +    'Height',
 +    'Gender',
 +    ]
 +# using Pandas column names without white spaces
 +names = [name.replace(' ', '_') for name in names]
 +print(names)
 +
 +namesfr = [
 +    'Largeur des épaules',
 +    'Largueur des hanches',
 +    'Largueur entre têtes de fémur',
 +    'Epaisseur du thorax',
 +    'Largueur du thorax',
 +    'Largueur du coude',
 +    'Largueur du poignet',
 +    'Largueur du genou',
 +    'Largueur de la cheville',
 +    'Tour d’épaules',
 +    'Tour de poitrine',
 +    'Tour de taille',
 +    'Tour au niveau du nombril',
 +    'Tour de hanches',
 +    'Tour de cuisse',
 +    'Tour du biceps',
 +    'Tour de l’avant-bras',
 +    'Tour de genou',
 +    'Plus grande circonférence du mollet',
 +    'Plus petite circonférence de la cheville',
 +    'Plus petite circonférence du poignet',
 +    'Âge',
 +    'Poids',
 +    'Taille',
 +    'Genre',
 +    ]
 +
 +dict_names_fr = dict(zip(names, namesfr))
 +print(dict_names_fr)
 +
 +file_url = "http://linus.umons.ac.be/body.dat.txt" # file copy
 +#file_url = "http://jse.amstat.org/datasets/body.dat.txt"
 +# using read_csv
 +# https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.read_csv.html
 +# https://www.datacamp.com/community/tutorials/pandas-read-csv
 +
 +df = pd.read_csv(file_url, header=None, names=names, delimiter='  | ', engine='python', index_col=False)
 +
 +print(df)
 +
 +# pandas misc
 +# https://stackoverflow.com/questions/15315452/selecting-with-complex-criteria-from-pandas-dataframe
 +#
 +print(df.columns)
 +print(df.Age)
 +print(df.dtypes)
 +print(df.describe())
 +print(df[df.Gender == 1].describe())
 +print(df[df.Age == 20].describe())
 +print(df.sort_values(by = 'Height'))
 +
 +print(df.query('Age > 25 and Age < 30'))
 +print(df.query('25 < Age < 30'))
 +
 +plt.figure()
 +ax = df[df.Gender == 1].plot.scatter(x='Height', y='Weight', color='Red', label='Male');
 +df[df.Gender == 0].plot.scatter(x='Height', y='Weight', color='Green', label='Female', ax=ax);
 +
 +plt.figure()
 +df.Height.plot.hist()
 +
 +plt.figure()
 +df.Weight.plot.hist()
 +</code>
  
 ===== Références ===== ===== Références =====
  • teaching/progappchim/pandas.txt
  • Dernière modification : 2022/11/15 10:08
  • de villersd