issue157:python
Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
issue157:python [2020/06/02 10:11] – d52fr | issue157:python [2020/06/06 13:52] (Version actuelle) – andre_domenech | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | **We are all experiencing a new world due to COVID-19. | + | **We are all experiencing a new world due to COVID-19. |
- | **We are presented with the number of confirmed cases, number of deaths and number of hospitalizations due to COVID-19 on every TV news show, radio show and on the Internet. | + | We are presented with the number of confirmed cases, number of deaths and number of hospitalizations due to COVID-19 on every TV news show, radio show and on the Internet. |
- | Way back in December 2018 (FCM#140), I talked about Pandas and Python. This month, we will use Pandas and Python to look at some of these numbers and make the graphs for ourselves. If you don’t have Pandas installed, please re-visit Full Circle Magazine # 140 to see the installation steps.** | + | Nous faisons tous l' |
- | **To get started, we need some data. I’m going to use a Comma Separated Variable data set available from https:// | + | À chaque journal télévisé, |
+ | |||
+ | **Way back in December 2018 (FCM#140), I talked about Pandas and Python. | ||
+ | |||
+ | To get started, we need some data. I’m going to use a Comma Separated Variable data set available from https:// | ||
When you get to the page, scroll down below the chart and find the first download “button” that says “time_series_covid19_confirmed_global.csv” to the left of it. This will download the CSV file to your machine. | When you get to the page, scroll down below the chart and find the first download “button” that says “time_series_covid19_confirmed_global.csv” to the left of it. This will download the CSV file to your machine. | ||
Now use LibreOffice Calc (or some other spreadsheet viewer) to open the file. In theory, you should be able to simply double click on the downloaded file. Accept the import settings box.** | Now use LibreOffice Calc (or some other spreadsheet viewer) to open the file. In theory, you should be able to simply double click on the downloaded file. Accept the import settings box.** | ||
+ | |||
+ | En décembre 2018 (le FCM n° 140), j'ai parlé de Pandas et Python. Ce mois-ci, nous utiliserons Pandas et Python pour regarder certains de ces chiffres et en faire des graphiques. Si Pandas n'est pas installé sur votre machine, retournez dans le FCM n° 140 pour les étapes de l' | ||
+ | |||
+ | Pour commencer, nous avons besoin de quelques données. Je vais utiliser un jeu de données CVS (Comma Separated Variables - Variables séparées par une virgule) disponible sur https:// | ||
+ | |||
+ | Quand vous arrivez sur la page, descendez sous le tableau et trouvez le premier bouton « download » qui indique « time_series_covid19_confirmed_global.csv » à sa gauche. Cela téléchargera le fichier .csv sur votre machine. | ||
+ | |||
+ | Maintenant, utilisez LibreOffice Calc (ou un autre tableur) pour ouvrir le fichier. En théorie, vous ne devriez avoir qu'à double-cliquer sur le fichier téléchargé. Acceptez la fenêtre des paramètres d' | ||
**PLEASE NOTE: I am using data that I downloaded on 5 May, 2020. Yours will be a little bit different, mainly in the fact that it will have more data, column wise as well as possibly more rows (since more regions can be added as new cases spread to more countries). | **PLEASE NOTE: I am using data that I downloaded on 5 May, 2020. Yours will be a little bit different, mainly in the fact that it will have more data, column wise as well as possibly more rows (since more regions can be added as new cases spread to more countries). | ||
The important thing to do here is to verify that the Country or Region that you are interested in is somewhere in Column B. It might be partially in Column B and partially in Column A. For example, if you are interested in Scotland, you would use the row marked “United Kingdom”, but if you want Greenland, you need to find “Denmark” in Column B then “Greenland” in Column A. For the purposes of this article, we’ll use “US” which is around row 227 (at least for now).** | The important thing to do here is to verify that the Country or Region that you are interested in is somewhere in Column B. It might be partially in Column B and partially in Column A. For example, if you are interested in Scotland, you would use the row marked “United Kingdom”, but if you want Greenland, you need to find “Denmark” in Column B then “Greenland” in Column A. For the purposes of this article, we’ll use “US” which is around row 227 (at least for now).** | ||
+ | |||
+ | MERCI DE NOTER : J' | ||
+ | |||
+ | La chose importante à faire ici est de vérifier que le pays ou la région qui vous intéresse est quelque part dans la colonne B. Elle peut être en partie dans la colonne B et en partie dans la colonne A. Par exemple, si vous vous intéressez à l' | ||
**Create a convenient folder somewhere, copy the CSV file into the folder and open a terminal window in that folder. | **Create a convenient folder somewhere, copy the CSV file into the folder and open a terminal window in that folder. | ||
Ligne 20: | Ligne 36: | ||
Look at the last line of the pandas head/tail dump. It says that there are 266 rows and 108 columns. | Look at the last line of the pandas head/tail dump. It says that there are 266 rows and 108 columns. | ||
+ | |||
+ | Créez un dossier quelque part à votre guise, copiez-y le fichier CSV et ouvrez une fenêtre de terminal dans ce dossier. (J' | ||
+ | |||
+ | Il est temps maintenant de faire un peu de codage. Nous utiliserons l’interpréteur Python pour cet exemple. Voyez l' | ||
+ | |||
+ | Regardez le dernière ligne de l' | ||
**Again, here we want to verify a few things. | **Again, here we want to verify a few things. | ||
Ligne 32: | Ligne 54: | ||
108 | 108 | ||
>>> | >>> | ||
+ | |||
+ | À nouveau, nous voulons vérifier quelques points. D' | ||
+ | |||
+ | Maintenant, nous avons des données avec lesquelles jouer. Mais nous avons besoin d'un peu plus d' | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | (266, 108) | ||
+ | >>> | ||
+ | >>> | ||
+ | 108 | ||
+ | >>> | ||
**Here we use data.shape() to get the number of rows and the number of columns in the dataframe. | **Here we use data.shape() to get the number of rows and the number of columns in the dataframe. | ||
Ligne 38: | Ligne 72: | ||
So we now have data that we can use, but the data was extracted, it came back as a data series, not a data frame. | So we now have data that we can use, but the data was extracted, it came back as a data series, not a data frame. | ||
+ | |||
+ | Ici, nous utilisons data.shape() pour obtenir le nombre de lignes et le nombre de colonnes du jeu de données. Cela est retourné comme un tuple ; aussi, nous pouvons assigner une variable « lastcol » aux 108 (sh[1]) de la variable sh. | ||
+ | |||
+ | Maintenant (en haut à droite), nous ne récupérerons que les colonnes qui contiennent le nombre de cas confirmés (Colonne E ou 4 - attention, début à zéro) via lastcol (108) pour la ligne 225. Nous utiliserons la méthode .iloc pour récupérer la ligne, la première et la dernière colonnes du jeu de données et les assigner à la variable sla. | ||
+ | |||
+ | Ainsi, nous avons maintenant des données que nous pouvons utiliser ; mais les données ont été extraites, sous la forme d'une série de données, pas d'un jeu de données. Aussi, nous devons les convertir en jeu de données. Voir en bas à droite. | ||
**So now we’ve got data that we can almost play with. But first, let’s assign the column headings to some proper, meaningful information. | **So now we’ve got data that we can almost play with. But first, let’s assign the column headings to some proper, meaningful information. | ||
Ligne 52: | Ligne 92: | ||
>>> | >>> | ||
+ | |||
+ | Ainsi, nous avons maintenant des données avec lesquelles jouer, ou presque. Mais d' | ||
+ | |||
+ | C'est un tracé très chargé (en bas à droite), mais vous pouvez vraiment voir le même genre de données que celles qui paraissent dans les journaux. | ||
+ | |||
+ | Pour la partie suivante de notre examen des données, nous devons calculer le nombre de nouveaux cas d'un jour sur l' | ||
+ | |||
+ | Maintenant, faisons apparaître les écarts quotidiens sur un graphique : | ||
+ | |||
+ | >>> | ||
+ | |||
+ | < | ||
+ | |||
+ | >>> | ||
**Now that you have the basics of dealing with the basic data, you can go back to the beginning, where we pulled the data for the US and change it to the country or region of your choice. | **Now that you have the basics of dealing with the basic data, you can go back to the beginning, where we pulled the data for the US and change it to the country or region of your choice. | ||
Ligne 66: | Ligne 120: | ||
You would change it to... | You would change it to... | ||
- | **s1a = data.iloc[175, | + | s1a = data.iloc[175, |
- | At this point, you would repeat all of the other steps again to create and modify the dataframe so you can plot it. | + | Maintenant que nous avons les bases pour traiter les données simples, vous pouvez retourner au début, là où nous avons extrait les données pour les USA et changer pour le pays ou la région de votre choix. Par exemple, modifiez la ligne : |
- | What exactly should we take away from this data? That’s a very good question. The accuracy of this, is currently in somewhat of a (series) question. | + | s1 = data.loc[data[' |
- | WIth a little bit of creative web searches, you can find a lot more information on Pandas, various datasets and types of plots and options that you can use to show your data. | + | en… |
+ | |||
+ | s1 = data.loc[data[' | ||
+ | |||
+ | Si vous imprimez les données de s1, vous verrez que la ligne de la Norvège est la 175. Aussi, avec la ligne suivante, nous n' | ||
+ | |||
+ | s1a = data.iloc[225, | ||
+ | |||
+ | vous pouvez la modifier en : | ||
+ | |||
+ | s1a = data.iloc[175, | ||
+ | |||
+ | **At this point, you would repeat all of the other steps again to create and modify the dataframe so you can plot it. | ||
+ | |||
+ | What exactly should we take away from this data? That’s a very good question. | ||
+ | |||
+ | À ce stade, vous pourriez répéter toutes les étapes précédentes pour créer et modifier les jeux de données de façon à les tracer. | ||
+ | |||
+ | Que devons-nous tirer vraiment de ces données ? C'est une très bonne question. La précision de celles-ci est actuellement une question (de séries) en elle-même. Il y a des spéculations qui suggèrent que le nombre de cas confirmés est bas dans beaucoup de régions du fait du manque de tests sur la population. Vous ne pouvez jamais être sûr des données, sauf si vous les regroupez vous-même. Dans des cas comme celui-ci, votre seul choix est de croire, avec un petit grain de sel, que les données ont été relevées avec le plus grand soin. | ||
+ | |||
+ | **WIth a little bit of creative web searches, you can find a lot more information on Pandas, various datasets and types of plots and options that you can use to show your data. | ||
Until next month; stay safe, healthy, positive and creative!** | Until next month; stay safe, healthy, positive and creative!** | ||
+ | |||
+ | Avec un peu de créativité dans vos recherches sur le Web, vous pouvez trouver beaucoup plus d' | ||
+ | |||
+ | Jusqu' | ||
+ | |||
//Lignes noires de l' | //Lignes noires de l' | ||
Ligne 81: | Ligne 160: | ||
**Now, we need to import two libraries, pandas and matplotlib.pyplot. | **Now, we need to import two libraries, pandas and matplotlib.pyplot. | ||
- | Maintenant, nous devons importer deux bibliothèques, | + | Maintenant, nous devons importer deux bibliothèques, |
**Now, let’s set the filename of the .csv file into a variable…** | **Now, let’s set the filename of the .csv file into a variable…** | ||
- | Maintenant, mettons le nom du fichier .csv dans une variable... | + | Maintenant, mettons le nom du fichier .csv dans une variable |
**Next, have Pandas read the spreadsheet into a dataframe…** | **Next, have Pandas read the spreadsheet into a dataframe…** | ||
- | Maintenant, faisons en sorte que Pandas lise le tableur | + | Puis, faisons en sorte que Pandas lise le tableur |
- | Lignes noires de l' | + | //Lignes noires de l' |
**Now we can plot the data. Remember, there are 104 data points, so the date information on the X axis will be pretty squished together.** | **Now we can plot the data. Remember, there are 104 data points, so the date information on the X axis will be pretty squished together.** | ||
- | Maintenant, nous pouvons tracer les données. | + | Maintenant, nous pouvons tracer les données. |
issue157/python.txt · Dernière modification : 2020/06/06 13:52 de andre_domenech