Photo by NASA on Unsplash

Member-only story

Python, Pandas and COVID-19

Prof Bill Buchanan OBE FRSE

--

We live in a modern world of data, and we should be using it in every way that we can to understand trends. But for many, it will be Microsoft Excel that they may turn to for any sort of analysis. But after Googling for transposing columns to rows, and then trying to merge row, you kinda give up.

The answer is to use Python and Pandas, and which allows us to quickly process data and get it into the right format. Let’s start on a data set which contains date, country, province, lat, long, confirmed cases, recovered cases, and deaths:

To say that we just want the current date (9 April 2020), and ignore all the other dates. For this we can create the code of:

import pandas as pdfilename = 'covid03.csv'date="2020-04-09"ds = pd.read_csv(filename)df = pd.DataFrame(ds)ds1 = df[df['Date'].str.contains(date)]print (ds1)

This will filter out all the rows which are not matched to ‘2020–04–09’ and will give:

       Date            Country/Region  ... Recovered  Deaths
78…

--

--

No responses yet