Having the dataset below. I would like to count the occurrences of a string in a certain year. In reality I have a much bigger dataframe a multiple years. How do I combine a groupby approach and count the different string values?
df = pd.DataFrame(data={'col1':['A','B','D','A'],'col2':['B','C','E','E'],'col3':['C','D','',''],'col4':['D','E','','']},index = ['01-01-2000','02-01-2000','01-01-2001','02-01-2001'])
col1 col2 col3 col4
01-01-2000 A B C D
02-01-2000 B C D E
01-01-2001 D E
02-01-2001 A E
desired result:
count
A 2000 1
A 2001 1
B 2000 2
B 2001 0
C 2000 2
C 2001 0
D 2000 2
D 2001 1
E 2000 1
E 2001 2