max_date = datetime.today().strftime('%d-%m-%Y')
min_date = "06-08-2021"
I have a df that looks like this. For now it only has 1 row:
name value
Name1 23
Then I have another dataset df2
that looks like this:
date group
07-08-2021 A
07-08-2021 A
06-08-2021 A
09-08-2021 A
07-08-2021 A
07-08-2021 B
06-08-2021 B
03-08-2020 A
I want to iterate through all rows of df2
and if the date if within the range of min_date
and max_date
, I want to do a cummulative sum of all occurences of A and B.
This means that I want to count the number of times a particular group type occured within that range. Then I want to add the that value to my first dataset. Something like this:
name value count_A count_B
Name1 23 5 2
Note that the last row:
03-08-2020 A
is not counted since the date doesn't fall in the range.
EDIT: sample df:
details = {
'Name' : ['Name1'],
'Value' : [23],
}
df1 = pd.DataFrame(details)
details = {
'Date' : ['07-08-2021', '07-08-2021', '06-08-2021', '09-08-2021','07-08-2021','07-08-2021','06-08-2021','03-08-2020'],
'Group' : ['A', 'A', 'A', 'A','A','B','B','A'],
}
df2 = pd.DataFrame(details)