From 855c1b1e9c9c6426aa3bcfeed308fd0713a3dd9e Mon Sep 17 00:00:00 2001 From: 6b9fcb02f874d4fa73786fcf6e721560 <6b9fcb02f874d4fa73786fcf6e721560@app-learninglab.inria.fr> Date: Sat, 2 May 2020 22:46:58 +0000 Subject: [PATCH] =?UTF-8?q?Filtres=20r=C3=A9gions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module3/exo3/exercice.ipynb | 1328 +++++------------------------------ 1 file changed, 171 insertions(+), 1157 deletions(-) diff --git a/module3/exo3/exercice.ipynb b/module3/exo3/exercice.ipynb index ea87754..677f446 100644 --- a/module3/exo3/exercice.ipynb +++ b/module3/exo3/exercice.ipynb @@ -23,19 +23,20 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 157, "metadata": {}, "outputs": [], "source": [ " %matplotlib inline\n", "import matplotlib.pyplot as plt\n", "import pandas as pd\n", - "import isoweek" + "import isoweek\n", + "import math" ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 158, "metadata": {}, "outputs": [ { @@ -1808,7 +1809,7 @@ "[266 rows x 105 columns]" ] }, - "execution_count": 4, + "execution_count": 158, "metadata": {}, "output_type": "execute_result" } @@ -1828,7 +1829,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 159, "metadata": {}, "outputs": [ { @@ -1889,7 +1890,7 @@ "[0 rows x 104 columns]" ] }, - "execution_count": 12, + "execution_count": 159, "metadata": {}, "output_type": "execute_result" } @@ -1907,14 +1908,28 @@ "\n", "## Seconde partie : génération montrant l'évolution de nombre de cas cumulé\n", "\n", - "On crée le tableau, en supprimant les pays qui ne nous intéressent pas. Pour cela, on crée un dictionnaire contenant les pays qui nous intéresse et retirer les autres. On va aussi retirer les colonnes longitude/latitude qui ne servent à rien ici :" + "On crée le tableau, en supprimant les pays et régions qui ne nous intéressent pas. Pour cela, on crée un dictionnaire contenant les pays qui nous intéresse et retirer les autres, dont la Chine que l'on a séparé du reste. \n", + "\n", + "On change Hong Kong en tant que pays pour pouvoir le voir plus tard sur le graphe.\n", + "On en profite pour retirer les colonnes longitude/latitude qui ne servent à rien ici :" ] }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 170, "metadata": {}, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Empty DataFrame\n", + "Columns: [1/22/20, 1/23/20, 1/24/20, 1/25/20, 1/26/20, 1/27/20, 1/28/20, 1/29/20, 1/30/20, 1/31/20, 2/1/20, 2/2/20, 2/3/20, 2/4/20, 2/5/20, 2/6/20, 2/7/20, 2/8/20, 2/9/20, 2/10/20, 2/11/20, 2/12/20, 2/13/20, 2/14/20, 2/15/20, 2/16/20, 2/17/20, 2/18/20, 2/19/20, 2/20/20, 2/21/20, 2/22/20, 2/23/20, 2/24/20, 2/25/20, 2/26/20, 2/27/20, 2/28/20, 2/29/20, 3/1/20, 3/2/20, 3/3/20, 3/4/20, 3/5/20, 3/6/20, 3/7/20, 3/8/20, 3/9/20, 3/10/20, 3/11/20, 3/12/20, 3/13/20, 3/14/20, 3/15/20, 3/16/20, 3/17/20, 3/18/20, 3/19/20, 3/20/20, 3/21/20, 3/22/20, 3/23/20, 3/24/20, 3/25/20, 3/26/20, 3/27/20, 3/28/20, 3/29/20, 3/30/20, 3/31/20, 4/1/20, 4/2/20, 4/3/20, 4/4/20, 4/5/20, 4/6/20, 4/7/20, 4/8/20, 4/9/20, 4/10/20, 4/11/20, 4/12/20, 4/13/20, 4/14/20, 4/15/20, 4/16/20, 4/17/20, 4/18/20, 4/19/20, 4/20/20, 4/21/20, 4/22/20, 4/23/20, 4/24/20, 4/25/20, 4/26/20, 4/27/20, 4/28/20, 4/29/20, 4/30/20, ...]\n", + "Index: []\n", + "\n", + "[0 rows x 101 columns]\n" + ] + }, { "data": { "text/html": [ @@ -1961,7 +1976,7 @@ " \n", "
\n", "68 rows × 103 columns
\n", + "25 rows × 103 columns
\n", "" ], "text/plain": [ - " Province/State Country/Region 1/22/20 1/23/20 \\\n", - "23 NaN Belgium 0 0 \n", - "49 Anhui China 1 9 \n", - "50 Beijing China 14 22 \n", - "51 Chongqing China 6 9 \n", - "52 Fujian China 1 5 \n", - "53 Gansu China 0 2 \n", - "54 Guangdong China 26 32 \n", - "55 Guangxi China 2 5 \n", - "56 Guizhou China 1 3 \n", - "57 Hainan China 4 5 \n", - "58 Hebei China 1 1 \n", - "59 Heilongjiang China 0 2 \n", - "60 Henan China 5 5 \n", - "61 Hong Kong China 0 2 \n", - "62 Hubei China 444 444 \n", - "63 Hunan China 4 9 \n", - "64 Inner Mongolia China 0 0 \n", - "65 Jiangsu China 1 5 \n", - "66 Jiangxi China 2 7 \n", - "67 Jilin China 0 1 \n", - "68 Liaoning China 2 3 \n", - "69 Macau China 1 2 \n", - "70 Ningxia China 1 1 \n", - "71 Qinghai China 0 0 \n", - "72 Shaanxi China 0 3 \n", - "73 Shandong China 2 6 \n", - "74 Shanghai China 9 16 \n", - "75 Shanxi China 1 1 \n", - "76 Sichuan China 5 8 \n", - "77 Tianjin China 4 4 \n", - ".. ... ... ... ... \n", - "111 New Caledonia France 0 0 \n", - "112 Reunion France 0 0 \n", - "113 Saint Barthelemy France 0 0 \n", - "114 St Martin France 0 0 \n", - "115 Martinique France 0 0 \n", - "116 NaN France 0 0 \n", - "120 NaN Germany 0 0 \n", - "133 NaN Iran 0 0 \n", - "137 NaN Italy 0 0 \n", - "139 NaN Japan 2 2 \n", - "166 Aruba Netherlands 0 0 \n", - "167 Curacao Netherlands 0 0 \n", - "168 Sint Maarten Netherlands 0 0 \n", - "169 NaN Netherlands 0 0 \n", - "184 NaN Portugal 0 0 \n", - "201 NaN Spain 0 0 \n", - "217 Bermuda United Kingdom 0 0 \n", - "218 Cayman Islands United Kingdom 0 0 \n", - "219 Channel Islands United Kingdom 0 0 \n", - "220 Gibraltar United Kingdom 0 0 \n", - "221 Isle of Man United Kingdom 0 0 \n", - "222 Montserrat United Kingdom 0 0 \n", - "223 NaN United Kingdom 0 0 \n", - "225 NaN US 1 1 \n", - "249 Anguilla United Kingdom 0 0 \n", - "250 British Virgin Islands United Kingdom 0 0 \n", - "251 Turks and Caicos Islands United Kingdom 0 0 \n", - "256 Bonaire, Sint Eustatius and Saba Netherlands 0 0 \n", - "258 Falkland Islands (Malvinas) United Kingdom 0 0 \n", - "259 Saint Pierre and Miquelon France 0 0 \n", + " Province/State Country/Region 1/22/20 1/23/20 \\\n", + "0 NaN Belgium 0 0 \n", + "1 NaN France 0 0 \n", + "2 NaN Germany 0 0 \n", + "3 NaN Iran 0 0 \n", + "4 NaN Italy 0 0 \n", + "5 NaN Japan 2 2 \n", + "6 Aruba Netherlands 0 0 \n", + "7 Curacao Netherlands 0 0 \n", + "8 Sint Maarten Netherlands 0 0 \n", + "9 NaN Netherlands 0 0 \n", + "10 NaN Portugal 0 0 \n", + "11 NaN Spain 0 0 \n", + "12 Bermuda United Kingdom 0 0 \n", + "13 Cayman Islands United Kingdom 0 0 \n", + "14 Channel Islands United Kingdom 0 0 \n", + "15 Gibraltar United Kingdom 0 0 \n", + "16 Isle of Man United Kingdom 0 0 \n", + "17 Montserrat United Kingdom 0 0 \n", + "18 NaN United Kingdom 0 0 \n", + "19 NaN US 1 1 \n", + "20 Anguilla United Kingdom 0 0 \n", + "21 British Virgin Islands United Kingdom 0 0 \n", + "22 Turks and Caicos Islands United Kingdom 0 0 \n", + "23 Bonaire, Sint Eustatius and Saba Netherlands 0 0 \n", + "24 Falkland Islands (Malvinas) United Kingdom 0 0 \n", "\n", - " 1/24/20 1/25/20 1/26/20 1/27/20 1/28/20 1/29/20 ... 4/22/20 \\\n", - "23 0 0 0 0 0 0 ... 41889 \n", - "49 15 39 60 70 106 152 ... 991 \n", - "50 36 41 68 80 91 111 ... 593 \n", - "51 27 57 75 110 132 147 ... 579 \n", - "52 10 18 35 59 80 84 ... 355 \n", - "53 2 4 7 14 19 24 ... 139 \n", - "54 53 78 111 151 207 277 ... 1582 \n", - "55 23 23 36 46 51 58 ... 254 \n", - "56 3 4 5 7 9 9 ... 147 \n", - "57 8 19 22 33 40 43 ... 168 \n", - "58 2 8 13 18 33 48 ... 328 \n", - "59 4 9 15 21 33 38 ... 921 \n", - "60 9 32 83 128 168 206 ... 1276 \n", - "61 2 5 8 8 8 10 ... 1033 \n", - "62 549 761 1058 1423 3554 3554 ... 68128 \n", - "63 24 43 69 100 143 221 ... 1019 \n", - "64 1 7 7 11 15 16 ... 194 \n", - "65 9 18 33 47 70 99 ... 653 \n", - "66 18 18 36 72 109 109 ... 937 \n", - "67 3 4 4 6 8 9 ... 106 \n", - "68 4 17 21 27 34 39 ... 146 \n", - "69 2 2 5 6 7 7 ... 45 \n", - "70 2 3 4 7 11 12 ... 75 \n", - "71 0 1 1 6 6 6 ... 18 \n", - "72 5 15 22 35 46 56 ... 279 \n", - "73 15 27 46 75 95 130 ... 787 \n", - "74 20 33 40 53 66 96 ... 639 \n", - "75 1 6 9 13 27 27 ... 197 \n", - "76 15 28 44 69 90 108 ... 561 \n", - "77 8 10 14 23 24 27 ... 189 \n", - ".. ... ... ... ... ... ... ... ... \n", - "111 0 0 0 0 0 0 ... 18 \n", - "112 0 0 0 0 0 0 ... 410 \n", - "113 0 0 0 0 0 0 ... 6 \n", - "114 0 0 0 0 0 0 ... 38 \n", - "115 0 0 0 0 0 0 ... 164 \n", - "116 2 3 3 3 4 5 ... 154715 \n", - "120 0 0 0 1 4 4 ... 150648 \n", - "133 0 0 0 0 0 0 ... 85996 \n", - "137 0 0 0 0 0 0 ... 187327 \n", - "139 2 2 4 4 7 7 ... 11512 \n", - "166 0 0 0 0 0 0 ... 100 \n", - "167 0 0 0 0 0 0 ... 14 \n", - "168 0 0 0 0 0 0 ... 71 \n", - "169 0 0 0 0 0 0 ... 34842 \n", - "184 0 0 0 0 0 0 ... 21982 \n", - "201 0 0 0 0 0 0 ... 208389 \n", - "217 0 0 0 0 0 0 ... 99 \n", - "218 0 0 0 0 0 0 ... 66 \n", - "219 0 0 0 0 0 0 ... 498 \n", - "220 0 0 0 0 0 0 ... 132 \n", - "221 0 0 0 0 0 0 ... 307 \n", - "222 0 0 0 0 0 0 ... 11 \n", - "223 0 0 0 0 0 0 ... 133495 \n", - "225 2 2 5 5 5 5 ... 840351 \n", - "249 0 0 0 0 0 0 ... 3 \n", - "250 0 0 0 0 0 0 ... 5 \n", - "251 0 0 0 0 0 0 ... 11 \n", - "256 0 0 0 0 0 0 ... 5 \n", - "258 0 0 0 0 0 0 ... 11 \n", - "259 0 0 0 0 0 0 ... 1 \n", + " 1/24/20 1/25/20 1/26/20 1/27/20 1/28/20 1/29/20 ... 4/22/20 \\\n", + "0 0 0 0 0 0 0 ... 41889 \n", + "1 2 3 3 3 4 5 ... 154715 \n", + "2 0 0 0 1 4 4 ... 150648 \n", + "3 0 0 0 0 0 0 ... 85996 \n", + "4 0 0 0 0 0 0 ... 187327 \n", + "5 2 2 4 4 7 7 ... 11512 \n", + "6 0 0 0 0 0 0 ... 100 \n", + "7 0 0 0 0 0 0 ... 14 \n", + "8 0 0 0 0 0 0 ... 71 \n", + "9 0 0 0 0 0 0 ... 34842 \n", + "10 0 0 0 0 0 0 ... 21982 \n", + "11 0 0 0 0 0 0 ... 208389 \n", + "12 0 0 0 0 0 0 ... 99 \n", + "13 0 0 0 0 0 0 ... 66 \n", + "14 0 0 0 0 0 0 ... 498 \n", + "15 0 0 0 0 0 0 ... 132 \n", + "16 0 0 0 0 0 0 ... 307 \n", + "17 0 0 0 0 0 0 ... 11 \n", + "18 0 0 0 0 0 0 ... 133495 \n", + "19 2 2 5 5 5 5 ... 840351 \n", + "20 0 0 0 0 0 0 ... 3 \n", + "21 0 0 0 0 0 0 ... 5 \n", + "22 0 0 0 0 0 0 ... 11 \n", + "23 0 0 0 0 0 0 ... 5 \n", + "24 0 0 0 0 0 0 ... 11 \n", "\n", - " 4/23/20 4/24/20 4/25/20 4/26/20 4/27/20 4/28/20 4/29/20 4/30/20 \\\n", - "23 42797 44293 45325 46134 46687 47334 47859 48519 \n", - "49 991 991 991 991 991 991 991 991 \n", - "50 593 593 593 593 593 593 593 593 \n", - "51 579 579 579 579 579 579 579 579 \n", - "52 355 355 355 355 355 355 355 356 \n", - "53 139 139 139 139 139 139 139 139 \n", - "54 1585 1585 1586 1587 1587 1588 1588 1588 \n", - "55 254 254 254 254 254 254 254 254 \n", - "56 147 147 147 147 147 147 147 147 \n", - "57 168 168 168 168 168 168 168 168 \n", - "58 328 328 328 328 328 328 328 328 \n", - "59 928 930 935 936 939 939 939 944 \n", - "60 1276 1276 1276 1276 1276 1276 1276 1276 \n", - "61 1035 1035 1037 1037 1037 1037 1037 1037 \n", - "62 68128 68128 68128 68128 68128 68128 68128 68128 \n", - "63 1019 1019 1019 1019 1019 1019 1019 1019 \n", - "64 194 197 198 198 199 199 200 201 \n", - "65 653 653 653 653 653 653 653 653 \n", - "66 937 937 937 937 937 937 937 937 \n", - "67 108 109 109 110 110 110 111 111 \n", - "68 146 146 146 146 146 146 146 146 \n", - "69 45 45 45 45 45 45 45 45 \n", - "70 75 75 75 75 75 75 75 75 \n", - "71 18 18 18 18 18 18 18 18 \n", - "72 279 286 286 286 286 306 306 306 \n", - "73 787 787 787 787 787 787 787 787 \n", - "74 641 641 642 642 644 645 647 652 \n", - "75 197 197 197 197 197 197 197 197 \n", - "76 561 561 561 561 561 561 561 561 \n", - "77 189 190 190 190 190 190 190 190 \n", - ".. ... ... ... ... ... ... ... ... \n", - "111 18 18 18 18 18 18 18 18 \n", - "112 412 412 417 417 418 418 420 420 \n", - "113 6 6 6 6 6 6 6 6 \n", - "114 38 38 38 38 38 38 38 38 \n", - "115 164 170 175 175 175 175 175 178 \n", - "116 157026 158636 160292 160847 164589 167605 165093 165764 \n", - "120 153129 154999 156513 157770 158758 159912 161539 163009 \n", - "133 87026 88194 89328 90481 91472 92584 93657 94640 \n", - "137 189973 192994 195351 197675 199414 201505 203591 205463 \n", - "139 12368 12829 13231 13441 14153 13736 13895 14088 \n", - "166 100 100 100 100 100 100 100 100 \n", - "167 14 16 16 16 16 16 16 16 \n", - "168 73 73 73 74 74 75 75 75 \n", - "169 35729 36535 37190 37845 38245 38416 38802 39316 \n", - "184 22353 22797 23392 23864 24027 24322 24505 25045 \n", - "201 213024 202990 205905 207634 209465 210773 212917 213435 \n", - "217 99 99 109 109 110 110 111 114 \n", - "218 66 70 70 70 70 70 73 73 \n", - "219 521 523 525 525 525 530 537 537 \n", - "220 133 133 136 141 141 141 141 144 \n", - "221 307 308 308 308 308 309 313 315 \n", - "222 11 11 11 11 11 11 11 11 \n", - "223 138078 143464 148377 152840 157149 161145 165221 171253 \n", - "225 869170 905358 938154 965785 988197 1012582 1039909 1069424 \n", - "249 3 3 3 3 3 3 3 3 \n", - "250 5 5 6 6 6 6 6 6 \n", - "251 11 11 11 11 12 12 12 12 \n", - "256 5 5 5 5 5 5 5 5 \n", - "258 12 13 13 13 13 13 13 13 \n", - "259 1 1 1 1 1 1 1 1 \n", + " 4/23/20 4/24/20 4/25/20 4/26/20 4/27/20 4/28/20 4/29/20 4/30/20 \\\n", + "0 42797 44293 45325 46134 46687 47334 47859 48519 \n", + "1 157026 158636 160292 160847 164589 167605 165093 165764 \n", + "2 153129 154999 156513 157770 158758 159912 161539 163009 \n", + "3 87026 88194 89328 90481 91472 92584 93657 94640 \n", + "4 189973 192994 195351 197675 199414 201505 203591 205463 \n", + "5 12368 12829 13231 13441 14153 13736 13895 14088 \n", + "6 100 100 100 100 100 100 100 100 \n", + "7 14 16 16 16 16 16 16 16 \n", + "8 73 73 73 74 74 75 75 75 \n", + "9 35729 36535 37190 37845 38245 38416 38802 39316 \n", + "10 22353 22797 23392 23864 24027 24322 24505 25045 \n", + "11 213024 202990 205905 207634 209465 210773 212917 213435 \n", + "12 99 99 109 109 110 110 111 114 \n", + "13 66 70 70 70 70 70 73 73 \n", + "14 521 523 525 525 525 530 537 537 \n", + "15 133 133 136 141 141 141 141 144 \n", + "16 307 308 308 308 308 309 313 315 \n", + "17 11 11 11 11 11 11 11 11 \n", + "18 138078 143464 148377 152840 157149 161145 165221 171253 \n", + "19 869170 905358 938154 965785 988197 1012582 1039909 1069424 \n", + "20 3 3 3 3 3 3 3 3 \n", + "21 5 5 6 6 6 6 6 6 \n", + "22 11 11 11 11 12 12 12 12 \n", + "23 5 5 5 5 5 5 5 5 \n", + "24 12 13 13 13 13 13 13 13 \n", "\n", - " 5/1/20 \n", - "23 49032 \n", - "49 991 \n", - "50 593 \n", - "51 579 \n", - "52 356 \n", - "53 139 \n", - "54 1588 \n", - "55 254 \n", - "56 147 \n", - "57 168 \n", - "58 328 \n", - "59 944 \n", - "60 1276 \n", - "61 1039 \n", - "62 68128 \n", - "63 1019 \n", - "64 201 \n", - "65 653 \n", - "66 937 \n", - "67 112 \n", - "68 146 \n", - "69 45 \n", - "70 75 \n", - "71 18 \n", - "72 306 \n", - "73 787 \n", - "74 652 \n", - "75 197 \n", - "76 561 \n", - "77 190 \n", - ".. ... \n", - "111 18 \n", - "112 422 \n", - "113 6 \n", - "114 38 \n", - "115 179 \n", - "116 165764 \n", - "120 164077 \n", - "133 95646 \n", - "137 207428 \n", - "139 14305 \n", - "166 100 \n", - "167 16 \n", - "168 76 \n", - "169 39791 \n", - "184 25351 \n", - "201 213435 \n", - "217 114 \n", - "218 74 \n", - "219 538 \n", - "220 144 \n", - "221 316 \n", - "222 11 \n", - "223 177454 \n", - "225 1103461 \n", - "249 3 \n", - "250 6 \n", - "251 12 \n", - "256 6 \n", - "258 13 \n", - "259 1 \n", + " 5/1/20 \n", + "0 49032 \n", + "1 165764 \n", + "2 164077 \n", + "3 95646 \n", + "4 207428 \n", + "5 14305 \n", + "6 100 \n", + "7 16 \n", + "8 76 \n", + "9 39791 \n", + "10 25351 \n", + "11 213435 \n", + "12 114 \n", + "13 74 \n", + "14 538 \n", + "15 144 \n", + "16 316 \n", + "17 11 \n", + "18 177454 \n", + "19 1103461 \n", + "20 3 \n", + "21 6 \n", + "22 12 \n", + "23 6 \n", + "24 13 \n", "\n", - "[68 rows x 103 columns]" + "[25 rows x 103 columns]" ] }, - "execution_count": 60, + "execution_count": 170, "metadata": {}, "output_type": "execute_result" } @@ -3693,25 +2700,32 @@ "source": [ "def filter_countries(row):\n", " countries = ['Belgium', 'China', 'France', 'Germany', 'Iran', 'Italy', 'Japan', 'Korea', 'Netherlands', 'Portugal', 'Spain', 'United Kingdom', 'US']\n", - " if any(str(row['Country/Region']) in s for s in countries):\n", + " if row['Country/Region'] in countries:\n", + " if str(row['Country/Region']) == 'France':\n", + " if str(row['Province/State']) == \"nan\":\n", + " return True\n", + " else:\n", + " return False\n", + " if str(row['Country/Region']) == 'China':\n", + " return False\n", " return True\n", "\n", " return False\n", "\n", + "only_china = new_data.loc[new_data['Country/Region'] == 'China']\n", + "only_china = only_china.loc[only_china['Province/State'] != 'Hong Kong']\n", + "only_china = only_china.drop(columns=['Province/State'])\n", + "only_china = only_china.groupby(['Country/Region']).sum()\n", + "print(only_china)\n", + "\n", "if len(raw_data.index) > 0:\n", " new_data = raw_data[raw_data.apply(filter_countries, axis=1)]\n", " \n", - "new_data = new_data.drop(columns=['Lat', 'Long'])\n", + "new_data = new_data.reset_index()\n", + "new_data = new_data.drop(columns=['Lat', 'Long', 'index'])\n", "new_data" ] }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "On va déjà essayer d'afficher le graphe avec toutes ces données, pour voir le résultat :" - ] - }, { "cell_type": "code", "execution_count": null, -- 2.18.1