1

My problem is simple: I have this csv file. I use Python 3. This file represent the number of new covid cases divided by country every day. But what I want to do is to obtain the global number of cases day by day regardless of the origin country. What is the fastest and simplest way to do this ?

Thank you

docdev
  • 943
  • 1
  • 7
  • 17
  • Does this answer your question? [Pandas group-by and sum](https://stackoverflow.com/questions/39922986/pandas-group-by-and-sum) – Henry Yik Dec 01 '20 at 14:36

1 Answers1

1

You could make a dictionary with dates as the key and cases as the value.

from datetime import datetime

cases_by_day = {}
with open("cases.csv") as f:
    f.readline()
    for line in f:
        elements = line.split(",")
        date = datetime.strptime(elements[0], "%d/%m/%Y")
        cases_by_day[date] = cases_by_day.get(date, 0) + int(elements[3])

This is easily expandable to add deaths and other data per day.