I have some monthly data that I'm trying to summarize using Pandas and I need to count the number of unique entries that occur each month.
I'm new to python / pandas dev, so i think i don't have the right reflexes yet.
I started here: Pandas Count Unique occurrences by Month
My source df look like this :
df = pd.DataFrame({'A' : ['08/10', '08/10', '09/10', '09/10',
'09/10', '10/10', '10/10', '10/10'],
'Name' : ['one', 'one', 'two', 'three',
'two', 'two', 'one', 'three'],
'C' : [1, 2, 3, 4, 5, 6, 7, 8],
'D' : ['sip:32800', 'sip:38800', 'sip:32800', 'sip:32800',
'sip:32800', 'sip:32800', 'sip:32800', 'sip:38800']
})
Desired Output:
Name 08/10 09/10 10/10
one 2 0 1
two 0 2 1
three 0 1 1
Optionally, I would like to filter on column "D", so as to count only the items of column 'B' if D contains "sip:32" for instance.
I can get the result using loops and iterations, but it doesn't perform well. I think there is much simpler using .groupby () .value_count (), but my tests are inconclusive.
Your help would be greatly appreciated.