0

I am working on a face detection and emotional recognition project. I would like to plot the emotion developments on a plot like this figure enter image description here Y-axis is the emotions and the X-axis is depending on the number of emotions registered (0 - len(emotions)). Any tips and ideas on this? This is what I tried to do but it did not work, enter image description here

sjsu
  • 17
  • 5
  • Please include a _small_ subset of your data as a __copyable__ piece of code that can be used for testing. See [MRE - Minimal, Reproducible, Example](https://stackoverflow.com/help/minimal-reproducible-example), and [How to make good reproducible pandas examples](https://stackoverflow.com/q/20109391/15497888) for more information. This leads to less guessing when it comes to determining the issue and can lead to better answers faster. Perhaps just the results of `print(df[df['Name'] == 'Jacki Chan'].to_dict())` – Henry Ecker Jul 20 '21 at 00:39

1 Answers1

0

You need to translate 'Happy' etc. to numbers, that's why you get the error ValueError: could not convert string to float: 'Happy'. You can get all unique emotions into a list and use the list index to specify numbers for each of them, for a new numeric column in your df. Here's one way:

df = pd.DataFrame({'Emotions': ['Happy', 'Disgust', 'Disgust', 'Happy']})

emotion_list = df['Emotions'].drop_duplicates().tolist()

for i, emotion in enumerate(emotion_list):
    df.loc[df['Emotions'] == emotion, 'emotion_as_number'] = i
    # or i + 1 if you want to start at 1 not 0

to get

  Emotions  emotion_as_number
0    Happy                1.0
1  Disgust                2.0
2  Disgust                2.0
3    Happy                1.0
Hammurabi
  • 1,141
  • 1
  • 4
  • 7