Find a sum of matching values of [a Python list] in a Pandas Dataframe cell?
<p><strong><em>Bottom line question:</em></strong> </p>

<p>This is ugly, right? For a pandas dataframe:</p>

<p><strong><code>happyBarFrame['Sunday'].apply(lambda x : x == [0]).value_counts()[0]</code></strong></p>

<p><strong><em>Long version:</em></strong> I am trying to find the sum of "empty" values in a Pandas Dataframe. Empty is when the entry is [0] -- a list.</p>

<p>I guess the best solution is not to use a list [0] as a value in a dataframe cell. Assuming I am sticking with that, I'd like to understand why so many functions don't work, giving a "unhashable list" error?</p>

<p>Yes this is a homework assignment for a data science class. We scrape a webpage that presents bars and happy hours. I have built this dataframe, I was using lists of hours where the last entry in the list is when the happy hour ends. Ignoring a couple bugs in the data:
<a href="https://i.stack.imgur.com/Oeb5D.png" rel="nofollow"><img src="https://i.stack.imgur.com/Oeb5D.png" alt="DataFrame of happy hours by day of week"></a></p>

<p>I am coming to believe that storing lists inside a dataframe is not the best idea, because many functions I would expect to work tell me they can't hash as list:</p>

<p><code>In [173]: happyBarFrame['Sunday'].value_counts()</code></p>

<p>... skipping long error ...</p>

<p><code>TypeError: unhashable type: 'list'</code></p>

<p><strong>Question is: I have tried the following, among many other things. What's the best approach to count the cells by day that have a list with a single 0 (cell value = [0])?</strong></p>

<p><code>happyBarFrame[happyBarFrame['Sunday'].isin([[0]])]</code> -- Doesn't work
<code>happyBarFrame[happyBarFrame['Sunday'].isin([0])]</code> -- Doesn't work</p>

<p>Both give <code>TypeError: unhashable type: 'list'</code></p>

<hr>

<p><strong><code>happyBarFrame['Sunday'].apply(lambda x : x == [0]).value_counts()[0]</code></strong></p>

<p><strong>Does work but just feels wrong!</strong> I can iterate through the days of the week, getting the count by day and then build the histogram I need to build. But there must be a better way, this seems really inefficient, true?</p>

<p>EDIT: Fixed a bug where need to count True, not False, in value_counts[0]</p>