0

A data frame in pandas with two columns "text", "Condition". In "Condition" column it contains numerical values for each row of "text". Values are 1,-1,0. I would like to convert these integer values to text labels, for instance, 1 for positive, -1 for negative and 0 for neutral. How can I achieve that?

Dataframe looks like:

Mohit Motwani
  • 4,662
  • 3
  • 17
  • 45
Saud
  • 43
  • 1
  • 11

1 Answers1

8

If I understood you question correctly here are the following ways you can change your values.

Using Series.map:

df['condition'] = df['condition'].map({1:'positive', -1:'negative', 0:'neutral'})

Using Series.replace:

df['condition'] = df['condition'].replace({1:'positive', -1:'negative', 0:'neutral'}}
Mohit Motwani
  • 4,662
  • 3
  • 17
  • 45