Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ jsconfig.json
/.luarc.json

**/*.quarto_ipynb
*.quarto_ipynb*
.vscode/
2 changes: 1 addition & 1 deletion _quarto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ project:
- 404.qmd
- content/getting-started/index.qmd
- content/manipulation/index.qmd
- content/manipulation/02_pandas_suite.qmd
- content/visualisation/index.qmd
- content/getting-started/01_environment.qmd
- content/modelisation/index.qmd
- content/modelisation/4_featureselection.qmd
- content/NLP/index.qmd
- content/annexes/corrections.qmd
- content/annexes/evaluation.qmd
Expand Down
1,596 changes: 826 additions & 770 deletions content/manipulation/02_pandas_suite.qmd

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions content/manipulation/02_pandas_suite/_exo3.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ On se focalise temporairement sur les observations où le libellé comporte plus

* _Question 4_. Pour mieux y voir, réordonner la base obtenue par order alphabétique.

* _Question 5_. Déterminer la taille moyenne (variable nombre de personnes: `NBPERSMENFISC16`) et quelques statistiques descriptives de ces données.
* _Question 5_. Déterminer la taille moyenne (variable nombre de personnes: `POPULATION`) et quelques statistiques descriptives de ces données.
Comparer aux mêmes statistiques sur les données où libellés et codes communes coïncident.

* _Question 6_. Vérifier les grandes villes (plus de 100 000 personnes),
Expand Down Expand Up @@ -46,7 +46,7 @@ We temporarily focus on observations where the label involves more than two diff

* _Question 4_. To get a better view, reorder the obtained dataset alphabetically.

* _Question 5_. Determine the average size (variable number of people: `NBPERSMENFISC16`) and some descriptive statistics of this data. Compare it to the same statistics on the data where labels and commune codes coincide.
* _Question 5_. Determine the average size (variable number of people: `POPULATION`) and some descriptive statistics of this data. Compare it to the same statistics on the data where labels and commune codes coincide.

* _Question 6_. Check the major cities (more than 100,000 people) for the proportion of cities where the same name is associated with different commune codes.

Expand Down
12 changes: 6 additions & 6 deletions content/manipulation/02_pandas_suite/_exo3_solution.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,30 @@ filosofi.loc[
print(10*"--" + "Communes dupliquées" + 10*"--")
print(
filosofi.loc[
filosofi['LIBGEO'].isin(doublons['LIBGEO']), 'NBPERSMENFISC16'
filosofi['LIBGEO'].isin(doublons['LIBGEO']), 'POPULATION'
].describe()
)
print(10*"--" + "Communes non dupliquées" + 10*"--")
print(
filosofi.loc[
~filosofi['LIBGEO'].isin(doublons['LIBGEO']), 'NBPERSMENFISC16'
~filosofi['LIBGEO'].isin(doublons['LIBGEO']), 'POPULATION'
].describe()
)
```

```{python}
#| output: false
# Question 6
emissions_big_city = filosofi.loc[filosofi['NBPERSMENFISC16']>100000].copy()
emissions_big_city = filosofi.loc[filosofi['POPULATION']>100000].copy()
emissions_big_city['probleme'] = emissions_big_city['LIBGEO'].isin(doublons['LIBGEO'])
emissions_big_city['probleme'].mean()
emissions_big_city['probleme'].mean()
emissions_big_city[emissions_big_city['probleme']]
print(100*emissions_big_city['probleme'].mean()) #8,33 %
print(100*emissions_big_city['probleme'].mean()) #9,52 %
```

```{python}
#| output: false
# Question 7
filosofi[filosofi['LIBGEO'] == 'Montreuil']
filosofi[filosofi['LIBGEO'].str.contains('Saint-Denis')].head(10)
filosofi[filosofi['LIBGEO'].str.contains('Saint-Denis', na=False)].head(10)
```
8 changes: 5 additions & 3 deletions content/manipulation/02_pandas_suite/_exo4_solution.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
#| output: false
# Question 1

emissions['emissions'] = emissions.sum(axis = 1, numeric_only = True)
emissions_totales_commune = emissions.sum(axis = 1, numeric_only = True)
```

```{python}
#| output: false
# Question 2

emissions_merged = (
emissions.reset_index()
emissions.assign(emissions = emissions_totales_commune)
.reset_index()
.merge(filosofi, left_on = "INSEE commune", right_on = "CODGEO")
)
```
Expand All @@ -19,7 +20,8 @@ emissions_merged = (
#| output: false
# Question 3

emissions_merged['empreinte'] = emissions_merged['emissions']/emissions_merged['NBPERSMENFISC16']
emissions_merged = emissions_merged.loc[emissions_merged['POPULATION'] > 0]
emissions_merged['empreinte'] = emissions_merged['emissions']/emissions_merged['POPULATION']
emissions_merged['empreinte'] = emissions_merged['empreinte'].astype(float)
```

Expand Down
12 changes: 7 additions & 5 deletions content/manipulation/02_pandas_suite/_exo5_preliminary.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ To ensure you are able to complete the next exercise, here is the dataframe requ

```{python}
#| echo: true
emissions['emissions'] = emissions.sum(axis = 1, numeric_only = True)
emissions_totales_commune = emissions.sum(axis = 1, numeric_only = True)

emissions_merged = (
emissions.reset_index()
emissions.assign(emissions = emissions_totales_commune)
.reset_index()
.merge(filosofi, left_on = "INSEE commune", right_on = "CODGEO")
)
emissions_merged['empreinte'] = emissions_merged['emissions']/emissions_merged['NBPERSMENFISC16']
emissions_merged = emissions_merged.loc[emissions_merged['POPULATION'] > 0]
emissions_merged['empreinte'] = emissions_merged['emissions']/emissions_merged['POPULATION']
emissions_merged['empreinte'] = emissions_merged['empreinte'].astype(float)
```
```

```{python}
#| echo: true
emissions_table = (
emissions_merged
.rename(columns={"dep_y": "dep", "NBPERSMENFISC16": "population", "MED16": "revenu"})
.rename(columns={"dep_y": "dep", "POPULATION": "population", "NIVVIE_MEDIAN": "revenu"})
.groupby("dep")
.agg({"empreinte": "sum", "revenu": "median", "population": "sum"}) #pas vraiment le revenu médian
.reset_index()
Expand Down