-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcanalStatPythonR.qmd
More file actions
245 lines (163 loc) · 9.03 KB
/
Copy pathcanalStatPythonR.qmd
File metadata and controls
245 lines (163 loc) · 9.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
---
title: "Python dans l'environnement du statisticien public"
subtitle: "Canal'Stat - 30/09/2022"
format:
revealjs:
slide-number: true
chalkboard:
buttons: false
preview-links: auto
# logo: images/logo_masa.png
css: styles.css
footer: Canal'Stat - 30/09/2022
resources:
- demo.pdf
---
## Qui sommes-nous ? {background="#43464B" transition="fade" transition-speed="fast"}
- François Semecurbe
[Chef du bureau des Statistiques Structurelles, Environnementales et Forestières]{style="color: #BABFC4;"}
- Benoit Mirouse
[Responsable Enquête TERUTI]{style="color: #BABFC4;"}
- Anaël Delorme
[Responsable des statistiques sur l'Aquaculture]{style="color: #BABFC4;"}
## Où sommes-nous ? {background="#43464B"}
```{r}
#| echo: false
#| fig-height: 5
library(leaflet)
leaflet() %>%
setView(lat = 43.604462, lng = 1.444247, zoom = 9) %>%
addTiles() %>% # Add default OpenStreetMap map tiles
addMarkers(lat=43.53315, lng=1.4865, popup="SSP - Complexe Agricole d'Auzeville")
```
## [ Tout allait bien... grâce à [R](https://www.r-project.org/) ! ]{style="color: white; background-color: #43464B"} {background-image="images/chateau.jpg"}
{.absolute .fragment top="100" left="10" width="600"}
{.absolute .fragment top="180" right="20" width="700"}
## [Mais... [Python](https://www.python.org/) débarque]{style="color: white;"} {background-image="images/orage.jpg" .smaller}
{.absolute .fragment top="100" left="110" width="400"}
{.absolute .fragment top="120" left="550" width="450"}
## [Python](https://www.python.org/) en 2 mots {background="#43464B" background-image="images/code_python.png" background-opacity="0.1"}
- Langage de programmation
- Open source et gratuit
- Utilisation de bibliothèques spécialisées s'adaptant aux métiers
- Très grande communauté d'utilisateurs et contributeurs
## Alors... que faire avec [Python](https://www.python.org/) dans nos équipes de stat publique ? {background="#43464B" background-image="images/python.jpg"}
## Et si ?... on faisait sans [Python](https://www.python.org/) {background="#43464B"}
{fig-align="center"}
# Et oui, [R](https://www.r-project.org/) c'est super ! ...
::: {.fragment .fade-in}
[Mais on se passe de tout ce que nous offre [Python](https://www.python.org/)]{style="color: #936AC3; font-size: 200%; font-weight: bold"}
{.absolute left=950 top=200 width="90px"}
:::
## [Jupyter](https://jupyter.org/) pour collaborer simplement sur nos données
{{< video src="images/video_jupyter.mp4" >}}
## Cartographie simplement
### Démo
[En ligne](https://calm-gorge-78401.herokuapp.com/){preview-link="true" style="text-align: center"}
Ou en vidéo : {{< video src="images/video greppo.mp4" >}}
## Cartographie simplement
### Code création des ronds
``` {.python code-line-numbers="1|2|4-9"}
variables = ["Recolte de bois", "Recolte de bois/Grumes", "Recolte de bois/Bois d'industrie", "Recolte de bois/Bois energie"]
colors = ['brown', 'green', 'blue', 'red']
ronds=list()
for i,v in enumerate(variables):
r = exf.centroid.buffer(1000*k*exf[v]**0.5)
r = gpd.GeoDataFrame(r,geometry=0)
r = r.to_crs(epsg=4326)
r = pd.merge(r, exf[[v,'Departement']], left_index=True, right_index=True)
ronds.append(r)
```
## Cartographie simplement
### Code création des couches
``` {.python code-line-numbers="1|2-7|8-11|12-21"}
app.display(name='title', value='Enquete EXFSRI')
for i in range(4):
app.vector_layer(
data=ronds[i],
name=variables[i],
style={"color":colors[i]},
visible=False,)
app.base_layer(
name="Open Street Map",
visible=True,
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",)
app.vector_layer(
data=reg,
name="Regions",
style={"color":'black', "fillOpacity":"0"},
visible=True,)
app.vector_layer(
data=dep,
name="Departements",
style={"color":'dimgrey', "fillOpacity":"0", "weight":"1"},
visible=False,)
```
## Cartographie simplement
### Ressources
[](https://docs.greppo.io/){preview-link="true" style="text-align: center"}
[Programmes sur le Github - bmirouse](https://github.com/bmirouse/Greppo-canal-stat-){preview-link="true" style="text-align: center"}
## [Analyse de textes](https://towardsai.net/p/data-mining/text-mining-in-python-steps-and-examples-78b3f8fd913b)
### A partir des réponses des enquêtés :

## [Analyse de textes](https://towardsai.net/p/data-mining/text-mining-in-python-steps-and-examples-78b3f8fd913b)
### Code
``` {.python code-line-numbers="6|8|10|12|14-18"}
import pandas as pd # Pour traiter les données
from wordcloud import WordCloud # Pour faire le nuage de mots
import matplotlib.pyplot as plt # le package de gestion des graphiques
from PIL import Image # masque d'image format poisson
commentaires = pd.read_csv('commentaire_aqua.csv', sep=';', engine='python', encoding='latin')
mots = commentaires['Q6.4'].str.lower().str.split(' ').sum()
stopwords = pd.read_csv("stop_words_french.txt", header=None)[0].tolist()
text = ' '.join([mot for mot in mots if mot not in stopwords])
wordcloud = wordcloud = WordCloud(width=6800, height=2800, max_words=60, colormap='RdYlGn',scale=3, background_color="white").generate(text)
plt.figure( figsize=(20,10), facecolor='k')
plt.imshow(wordcloud, interpolation='bilinear')
plt.axis("off")
plt.show();
```
## Et plein d'autres choses
- [Web scraping](https://www.edureka.co/blog/web-scraping-with-python/) : extraire des données directement de sites internet
{position=center}
<!-- {.absolute top=400 left=850 width="20%"} -->
- [Machine Learning](https://makina-corpus.com/data-science/initiation-au-machine-learning-avec-python-la-theorie) : créer des systèmes qui apprennent en fonction des données qui traitent.
[Exemple : reconnaissance d'images, recommandation de produits, détection de fraudes...]{style="font-size: 60%; font-weight: italic"}
[Tutoriels sur le [SSP Cloud](https://www.sspcloud.fr/formation)]{.aside style="font-size: 80%; font-weight: italic"}
# Ok [Python](https://www.python.org/) c'est top ! ...
::: {.fragment .fade-in}
[Alors on fait tout en [Python](https://www.python.org/), et on arrête [R](https://www.r-project.org/) ?]{style="color: #936AC3; font-size: 200%; font-weight: bold"}
{.absolute left=500 top=260 width="140px"}
:::
## On vous l'a dit : *[R](https://www.r-project.org/) c'est super !*
Se passer de [R](https://www.r-project.org/) est possible, mais cela nous ferait passer à côté :
:::: {.columns}
::: {.column width="20%"}
{width="70%"}
{width="40%"}


:::
::: {.column width="80%"}
- [Tidyverse](https://www.tidyverse.org/){preview-link="true" style="text-align: center"} : rapide, simple, efficace
- pour la préparation de données
- pour la création de graphiques
- [RStudio](https://www.rstudio.com/){preview-link="true" style="text-align: center"} : outil *clé en mains*
- [Shiny](https://shiny.rstudio.com/){preview-link="true" style="text-align: center"} : création facile de petites applications
- [Quarto](https://quarto.org/){preview-link="true" style="text-align: center"} : diffusion (pdf, internet...)
:::
::::
# ...[R](https://www.r-project.org/) + [Python](https://www.python.org/) ensemble, est-ce possible ? {background-image="images/coeur.jpg" background-opacity="0.25"}
## Cohabitation naturelle entre ces 2 langages
- Possible d'utiliser des programmes [R](https://www.r-project.org/) et [Python](https://www.python.org/) dans un même projet de développement
- [Quarto](https://quarto.org/){preview-link="true" style="text-align: center"} : [R](https://www.r-project.org/) et du [Python](https://www.python.org/) ensemble nativement
- [Shiny](https://shiny.rstudio.com/py/){preview-link="true" style="text-align: center"} : nouvelle version en [Python](https://www.python.org/)
- Outils de dév ([RStudio](https://www.rstudio.com/){preview-link="true" style="text-align: center"}, [VS Code](https://code.visualstudio.com/)) permettent de faire les 2
## Idée à discuter : prendre le meilleur des 2 mondes {background="#14243E"}

## Merci !{background="#43464B" background-video="images/sousmarin.mp4" background-video-loop="true" background-video-muted="true"}
Cette présentation a été réalisée avec Quarto :
- les sources sont disponibles sur [Github : https://github.com/anaelDelorme/pythonCanalStat](https://github.com/anaelDelorme/pythonCanalStat)
- la présentation est accessible sur [Github - Pages : https://anaeldelorme.github.io/pythonCanalStat/](https://anaeldelorme.github.io/pythonCanalStat/canalStatPythonR.html)
- les images proviennent de [Pixabay](https://pixabay.com/fr) et de [Storyset](https://storyset.com/)
## [Qu'en pensez-vous ?]{style="font-size: 170%; font-weight: bold"} {background-image="images/discussion.png"}