Let's say I have a dataframe:
date | brand | color
--------------------
2017 | BMW | red
2017 | GM | blue
2017 | BMW | blue
2017 | BMW | red
2018 | BMW | green
2018 | GM | blue
2018 | GM | blue
2018 | GM | red
As a result I want to have something like:
date | brand | red | blue | green
---------------------------------
2017 | BMW | 2 | 1 | 0
| GM | 0 | 1 | 0
2018 | BMW | 0 | 0 | 1
| GM | 1 | 2 | 0
I found that I need to use groupby + size, something like:
df[df['color'] == 'red'].groupby([df['date'], df['brand']]).size()
But this gives me Series only for single color, while I want to have complete dataframe as shown higher.
df['color'] == 'red'?