I have time-indexed data:
df2 = pd.DataFrame({ 'day': pd.Series([date(2012, 1, 1), date(2012, 1, 3), date(2012, 1, 5)]), 'a' : pd.Series(['A', 'B', 'C']),
'b': pd.Series(['C', 'E', 'C']), 'c': pd.Series(['E', 'F', 'A']), 'd': pd.Series(['B', np.nan, 'E'])})
df2 = df2.set_index('day')
df2
a b c d
day
2012-01-01 A C E B
2012-01-03 B E F NaN
2012-01-05 C C A E
What is the best way to reshape the table to get the frequency of each unique value each day?
for example, A occurs once on 1/01 and 1/05.
So the desired result would be:
A B C D E F NaN
day
2012-01-01 1 1 1 0 1 0 0
2012-01-03 0 1 0 0 1 1 1
2012-01-05 1 0 2 0 1 0 0
Many thanks!