I have a df column that has values ranging from -5 to 10. I want to change values <= -1 to negative, all 0 values to neutral, and all values >=
negative
neutral
Another alternative is to define a custom function:
def transform_sentiment(x): if x < 0: return 'Negative' elif x == 0: return 'Neutral' else: return 'Positive' df['Sentiment_new'] = df['Sentiment'].apply(lambda x: transform_sentiment(x))