0

I have a column named "numbers" in which there are 100 values at random numbered from 1 to 5, and I have to create another column, "text" in which there will be the names corresponding to the value as defined for 1 to 5. 1: Surprise
2: Fear
3: Disgust
4: Happy
5: Sad

enter image description here
How to do this?

Saurav
  • 75
  • 8
  • 2
    Hi you should give some more detail: What "columns" are these? In a CSV, dataframe? And what does your current code look like? – patrick Jan 11 '21 at 16:16

1 Answers1

2

Something like this?

import pandas as pd
df = pd.DataFrame([[1], [2], [3], [2], [5], [3], [1]])
df["text"] = df[0].map({1 : 'Surprise', 2 : 'Fear', 3 : 'Disgust', 4 : 'Happy', 5: 'Sad'})
print(df)
pascscha
  • 1,623
  • 10
  • 16