Pandas: Expand column containing list into new column variables with cells representing count
<p>I started by data set with individual click data. I have aggregated the data in a yearly fashion to build a time series. But one of the problem I ran is aggregating click's source (example where click came from). As a result of that after aggregating I have following data frame.</p>

<pre><code>    year  month  clickSource
0   2010    01  google, yahoo, google, google, facebook, facebook
1   2010    02  facebook, yahoo, google, google, facebook, facebook
2   2010    03  yahoo, yahoo, google, google, facebook, facebook
3   2010    04  google, yahoo, google, twitter, facebook, facebook
4   2010    05  facebook, yahoo, google, google, facebook, facebook
5   2010    06  twitter, yahoo, google, twitter, facebook, google
</code></pre>

<p>I want to introduce column to each unique item in the <code>clickSource</code> column's along with the count example: </p>

<pre><code>    year  month  google  yahoo  facebook  twitter
0   2010    01    3       1         2       0
1   2010    02    2       1         3       0   
2   2010    03    2       2         2       0 
...
</code></pre>

<p>Initially my column was a string object so I covert it to list as fallows: </p>

<pre><code>temp['clickSource'] = temp['clickSource'].apply(lambda x: x.split(','))
</code></pre>

<p>Then I made a series: </p>

<pre><code>col_names = temp['clickSource'].apply(pd.Series)
</code></pre>

<p>But this created a column for every item in the list instead once per item (obviously because I didn't tell it to count etc). How to I obtain what I explained? </p>