-1

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,322
  • 3
  • 17
  • 40
Saud
  • 33
  • 11

1 Answers1

4

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,322
  • 3
  • 17
  • 40