【问题标题】:Plot emotion development based on pandas dataframe基于 pandas 数据框绘制情感发展
【发布时间】:2021-09-27 13:39:48
【问题描述】:

我正在从事人脸检测和情绪识别项目。我想在这个图这样的情节上绘制情感发展 Y 轴是情绪,X 轴取决于记录的情绪数量 (0 - len(emotions))。对此有任何提示和想法吗? 这是我尝试做的,但没有成功,

【问题讨论】:

标签: python pandas matplotlib plot graph


【解决方案1】:

您需要将 'Happy' 等转换为数字,这就是您收到错误 ValueError: could not convert string to float: 'Happy' 的原因。您可以将所有独特的情绪放入一个列表中,并使用列表索引为每个情绪指定数字,为您的 df 中的新数字列指定数字。这是一种方法:

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

得到

  Emotions  emotion_as_number
0    Happy                1.0
1  Disgust                2.0
2  Disgust                2.0
3    Happy                1.0

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-09-29
    • 1970-01-01
    • 2014-03-28
    • 1970-01-01
    • 2019-04-20
    • 2015-08-03
    • 1970-01-01
    • 2021-11-28
    相关资源
    最近更新 更多