title: Python - 'TypeError: '<=' not supported between instances of 'str' and 'int''
body: <p>I have a df column that has values ranging from -5 to 10. I want to change values &lt;= -1 to <code>negative</code>, all 0 values to <code>neutral</code>, and all values >= 1 to <code>positive</code>. The code below, however, produces the following error for 'negative'. </p>
  
  <pre><code># Function to change values to labels
  
  test.loc[test['sentiment_score'] &gt; 0, 'sentiment_score'] = 'positive'
  test.loc[test['sentiment_score'] == 0, 'sentiment_score'] = 'neutral'
  test.loc[test['sentiment_score'] &lt; 0, 'sentiment_score'] = 'negative'
  
  Data:                                  Data After Code:
  Index     Sentiment                    Index     Sentiment
   0         2                            0         positive
   1         0                            1         neutral
   2        -3                            2         -3
   3         4                            3         positive
   4        -1                            4         -1
   ...                                    ...
   k         5                            k         positive
  </code></pre>
  
  <blockquote>
    <p>File "pandas_libs\ops.pyx", line 98, in pandas._libs.ops.scalar_compare
     TypeError: '&lt;=' not supported between instances of 'str' and 'int</p>
  </blockquote>
  
  <p>I assume that this has something to do with the function seeing negative numbers as string rather than float/int, however I've tried the following code to correct this error and it changes nothing. Any help would be appreciated.</p>
  
  <pre><code>test['sentiment_score'] = test['sentiment_score'].astype(float)
  test['sentiment_score'] = test['sentiment_score'].apply(pd.as_numeric)
  </code></pre>