title: Pandas Groupby ValueError: The truth value of a DataFrame is ambiguous
body: <p>I create a new DataFrame from a SQL query using Pandas's read_sql_query function.</p>
  
  <p>When iterating through the DataFrame, there are several dimension columns we do a groupby function, and it often works. However, for certain columns it will not and instead I get an error. The error is:</p>
  
  <pre><code>ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
  </code></pre>
  
  <p>In my attempt to replicate the issue, I created a dict and turned it into a DataFrame. This new DataFrame also has values (strings) that were unique. The groupby function works as it should. It appears that maybe if the DataFrame was created from a sql query, it has issues with groupby? Because I cannot reproduce      the issue outside of a query to our database (PostgreSQL) I cannot past anything run-able here. Below is the code I use to create the DataFrame from SQL</p>
  
  <pre><code>cur = conn.cursor()
  query ="""SELECT * from table1""" 
  df = pd.read_sql_query(query, conn)
  df['date'] = pd.to_datetime(df['date'])
  df = df.set_index(pd.DatetimeIndex(df['date'])) 
  </code></pre>
  
  <p>I don't think there's anything crazy with how I'm doing the above.</p>
  
  <p>Trackback:</p>
  
  <pre><code>---------------------------------------------------------------------------
  ValueError                                Traceback (most recent call last)
  &lt;ipython-input-410-83c5166962e7&gt; in &lt;module&gt;()
        5 
        6 df1 = df.drop(['client_name', 'class_type', 'message', 'from_name', 'from_id'], axis=1)
  ----&gt; 7 df1.groupby('post_id').sum()
        8 
        9 #             current_data = current_data.set_index(dim)
  
  /Users/Dev/anaconda/lib/python2.7/site-packages/pandas/core/generic.pyc in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze)
     3157         axis = self._get_axis_number(axis)
     3158         return groupby(self, by=by, axis=axis, level=level, as_index=as_index,
  -&gt; 3159                        sort=sort, group_keys=group_keys, squeeze=squeeze)
     3160 
     3161     def asfreq(self, freq, method=None, how=None, normalize=False):
  
  /Users/Dev/anaconda/lib/python2.7/site-packages/pandas/core/groupby.pyc in groupby(obj, by, **kwds)
     1197         raise TypeError('invalid type: %s' % type(obj))
     1198 
  -&gt; 1199     return klass(obj, by, **kwds)
     1200 
     1201 
  
  /Users/Dev/anaconda/lib/python2.7/site-packages/pandas/core/groupby.pyc in __init__(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze)
      386         if grouper is None:
      387             grouper, exclusions, obj = _get_grouper(obj, keys, axis=axis,
  --&gt; 388                                                     level=level, sort=sort)
      389 
      390         self.obj = obj
  
  /Users/Dev/anaconda/lib/python2.7/site-packages/pandas/core/groupby.pyc in _get_grouper(obj, key, axis, level, sort)
     2152             in_axis, name = False, None
     2153 
  -&gt; 2154         if is_categorical_dtype(gpr) and len(gpr) != len(obj):
     2155             raise ValueError("Categorical dtype grouper must have len(grouper) == len(data)")
     2156 
  
  /Users/Dev/anaconda/lib/python2.7/site-packages/pandas/core/generic.pyc in __nonzero__(self)
      712         raise ValueError("The truth value of a {0} is ambiguous. "
      713                          "Use a.empty, a.bool(), a.item(), a.any() or a.all()."
  --&gt; 714                          .format(self.__class__.__name__))
      715 
      716     __bool__ = __nonzero__
  
  ValueError: The truth value of a DataFrame is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
  </code></pre>