Feb-20-2021, 07:11 PM
If anything is to be counted my first thought is to go for Counter which happens to be Python's data type for counting.
Assuming that file data.csv containing sample data one can achieve desired output (in descending order):
Assuming that file data.csv containing sample data one can achieve desired output (in descending order):
from collections import Counter from datetime import datetime as dt with open('data.csv', 'r') as f: count = Counter() for line in f: _, marker, qty, item = line.strip().split(',') count.update({item: int(qty)}) timestamp = dt.today().date().strftime("%d/%m/%Y") for item, qty in count.most_common(): # for ascending order: count.most_common()[::-1] print(f'{timestamp},{marker},{qty},{item}') 20/02/2021,P,20,fish 20/02/2021,P,15,dog 20/02/2021,P,10,cat
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.