|
| 1 | +::: {.content-visible when-profile="fr"} |
| 2 | +:::: {.exercise} |
| 3 | +## Exercice 3 |
| 4 | + |
| 5 | +La base en question contient des livres de la British Library et quelques informations les concernant. Le jeu de données est disponible ici : https://raw.githubusercontent.com/realpython/python-data-cleaning/master/Datasets/BL-Flickr-Images-Book.csv |
| 6 | + |
| 7 | +La colonne "Date de Publication" n'est pas toujours une année, il y a parfois d'autres informations. Le but de l'exercice est d'avoir **une date de publication du livre propre** et de regarder la **distribution des années de publications**. |
| 8 | + |
| 9 | +Pour ce faire, vous pouvez : |
| 10 | + |
| 11 | +* Soit choisir de réaliser l'exercice sans aide. Votre **lecture de l'énoncé s'arrête donc ici**. Vous devez alors faire attention à bien regarder vous-même la base de données et la transformer avec attention. |
| 12 | + |
| 13 | +* Soit suivre les différentes étapes qui suivent pas à pas. |
| 14 | + |
| 15 | +```{=html} |
| 16 | +<details><summary>Version guidée 👇</summary> |
| 17 | +``` |
| 18 | + |
| 19 | +1. Lire les données depuis l'url `https://raw.githubusercontent.com/realpython/python-data-cleaning/master/Datasets/BL-Flickr-Images-Book.csv`. Attention au séparateur |
| 20 | +2. Ne garder que les colonnes `['Identifier', 'Place of Publication', 'Date of Publication', 'Publisher', 'Title', 'Author']` |
| 21 | +3. Observer la colonne _'Date of Publication'_ et remarquer le problème sur certaines lignes (par exemple la ligne 13) |
| 22 | +4. Commencez par regarder le nombre d'informations manquantes. On ne pourra pas avoir mieux après la regex, et normalement on ne devrait pas avoir moins... |
| 23 | +5. Déterminer la forme de la regex pour une date de publication. A priori, il y a 4 chiffres qui forment une année. |
| 24 | +Utiliser la méthode `str.extract()` avec l'argument `expand = False` (pour ne conserver que la première date concordant avec notre _pattern_)? |
| 25 | +6. On a 2 `NaN` qui n'étaient pas présents au début de l'exercice. Quels sont-ils et pourquoi ? |
| 26 | +7. Quelle est la répartition des dates de publications dans le jeu de données ? Vous pouvez par exemple afficher un histogramme grâce à la méthode `plot` avec l'argument `kind ="hist"`. |
| 27 | + |
| 28 | +```{=html} |
| 29 | +</summary> |
| 30 | +``` |
| 31 | + |
| 32 | +:::: |
| 33 | +::: |
| 34 | + |
| 35 | +::: {.content-visible when-profile="en"} |
| 36 | +:::: {.exercise} |
| 37 | +## Exercise 3 |
| 38 | + |
| 39 | +The dataset in question contains books from the British Library and some related information. The dataset is available here: https://raw.githubusercontent.com/realpython/python-data-cleaning/master/Datasets/BL-Flickr-Images-Book.csv |
| 40 | + |
| 41 | +The "Date of Publication" column is not always a year; sometimes there are other details. The goal of the exercise is to have **a clean book publication date** and to examine the **distribution of publication years**. |
| 42 | + |
| 43 | +To do this, you can: |
| 44 | + |
| 45 | +* Either choose to perform the exercise without help. Your **reading of the instructions ends here**. You should carefully examine the dataset and transform it yourself. |
| 46 | + |
| 47 | +* Or follow the step-by-step instructions below. |
| 48 | + |
| 49 | +```{=html} |
| 50 | +<details><summary>Guided version 👇</summary> |
| 51 | +``` |
| 52 | + |
| 53 | +1. Read the data from the URL `https://raw.githubusercontent.com/realpython/python-data-cleaning/master/Datasets/BL-Flickr-Images-Book.csv`. Be careful with the separator. |
| 54 | +2. Keep only the columns `['Identifier', 'Place of Publication', 'Date of Publication', 'Publisher', 'Title', 'Author']`. |
| 55 | +3. Observe the _'Date of Publication'_ column and note the issues with some rows (e.g., row 13). |
| 56 | +4. Start by looking at the number of missing values. We cannot do better after regex, and normally we should not have fewer... |
| 57 | +5. Determine the regex pattern for a publication date. Presumably, there are 4 digits forming a year. Use the `str.extract()` method with the `expand = False` argument (to keep only the first date matching our pattern)? |
| 58 | +6. We have 2 `NaN` values that were not present at the start of the exercise. What are they and why? |
| 59 | +7. What is the distribution of publication dates in the dataset? You can, for example, display a histogram using the `plot` method with the `kind = "hist"` argument. |
| 60 | + |
| 61 | +```{=html} |
| 62 | +</summary> |
| 63 | +``` |
| 64 | + |
| 65 | +:::: |
| 66 | +::: |
0 commit comments