pandas crashes on series with multiple data types
<p>I have a simple excel file with two columns - one categorical column and another numerical column that i read into pandas with the read_excel function as below</p>

<pre><code>df= pd.read_excel('pandas_crasher.xlsx')
</code></pre>

<p>The first column is of type Object with multiple types. Since the excel was badly formatted, the column contains a combination of timestamps, floats and texts. But its normally supposed to be just a simple textual column</p>

<pre><code>from datetime import datetime
from collections import Counter

df['random_names'].dtype 
</code></pre>

<blockquote>
  <p>dtype('O')</p>
</blockquote>

<p><strong><code>print Counter([type(i) for i in load_instance['random_names']])</code></strong></p>

<blockquote>
  <p>Counter({type 'unicode'>: 15427, type 'datetime.datetime'>: 18,
  type 'float'>: 2})</p>
</blockquote>

<p>When i do a simple groupby on it, it <strong><code>crashes the python kernel</code></strong> without any error messages or notifications - i tried doing it from both jupyter and a small custom flask app without any luck. </p>

<p><strong><code>df.groupby('random_names')['random_values'].sum()</code></strong> &lt;&lt; crashes</p>

<p>Its a relatively small file of 700kb (15k rows and 2 cols) - so its definitely not a memory issue</p>

<p>I tried debugging with pdb to trace the point at which crashes but couldnt get past the the cython function in the pandas/core/<a href="https://github.com/pydata/pandas/blob/v0.17.1/pandas/core/groupby.py" rel="nofollow">groupby.py module</a> </p>

<blockquote>
  <p>def _cython_operation(self, kind, values, how, axis)</p>
</blockquote>

<p>a possible bug in pandas - instead of crashing directly shouldnt it throw an exception and quit gracefully ?</p>

<p>I then convert the various datatypes into text with the following function</p>

<pre><code>def custom_converter(x):
    if isinstance(x,datetime)  or isinstance( x, ( int, long, float ) ):
        return str(x)
    else:
        return x.encode('utf-8')

df['new_random_names'] = df['random_names'].apply(custom_converter)

df['new_random_names'].groupby('random_names')['random_values'].sum() &lt;&lt; does not crash
</code></pre>

<p>The apply custom function is probably the slowest way of doing this. Is there any better/faster way of doing this ?</p>

<p>Excel file here: <a href="https://drive.google.com/file/d/0B1ZLijGO6gbLelBXMjJWRFV3a2c/view?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0B1ZLijGO6gbLelBXMjJWRFV3a2c/view?usp=sharing</a></p>