I have a pandas dataframe that contains data that looks like this:
levels char_1 char_2
a dog dog
a cat dog
b cow cat
b dog dog
I'd like to group_by the levels column and compute the total number of times that a value appears either in the char_1 column or char_2 column
The resulting dataframe would look like:
levels char count
a dog 3
a cat 1
b dog 2
b cow 1
b cat 1
I've experimented with pivot tables, but can't wrap my head around pandas syntax.