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?
Asked
Active
Viewed 4,280 times
0
-
Do you want to convert 1 to 'positive' and similarly to others? – Mohit Motwani Feb 08 '19 at 10:46
-
yes @Mohit, that is my target for now. I have tried several ways to map but all in vain – Saud Feb 08 '19 at 10:47
-
Can you add your dataframe as text instead of an image. It's easier for others to understand. – Mohit Motwani Feb 08 '19 at 11:00
1 Answers
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