I have a list in which each value is a list of tuples. for example, this is the value I am retrieving for the key:
[('1998-01-20',8) , ('1998-01-22',4) , ('1998-06-18',8 ) , ('1999-07-15' , 7), ('1999-07-21',1) ]
I also sorted the list. now I want to aggregate the values ββas follows:
[('1998-01' , 12 ) , ('1998-06' ,8 ) , ('1999-07',8 )]
in a way, I want to group my tuples in terms of a month, to summarize the ints for each month together, I read about groupby, and I think this cannot help me with my data structure, because I have no idea that Iβll come across on my list, so Iβm trying to find a way to say: start with the first elements of the tuples if I [0] [: 6] are equal: sum i [1]. but itβs hard for me to fulfill this idea.
for i in List : if i[0][:6] # *problem* I don't know how to say my condition : s=sum(i[1]) #?
Any advice would be appreciated since I am a new python user!
python list aggregate
Singu
source share