这是我的代码:
mapping = {"ISTJ":1, "ISTP":2, "ISFJ":3, "ISFP":4, "INFP":6, "INTJ":7, "INTP":8, "ESTP":9, "ESTJ":10, "ESFP":11, "ESFJ":12, "ENFP":13, "ENFJ":14, "ENTP":15, "ENTJ":16, "NaN": 17}
q20 = castaway_details["personality_type"]
q20["personality_type"] = q20["personality_type"].map(mapping)
Dataframe 如下所示
personality_type
0 INTP
1 INFP
2 INTJ
3 ISTJ
4 NAN
5 ESFP
我希望输出如下:
personality_type
0 8
1 6
2 7
3 1
4 17
5 11
但是,我从代码中得到都是NAN
2条答案
按热度按时间fjnneemd1#
尝试
pandas.Series.str.strip
之前的pandas.Series.map
:#输出:
yzuktlbb2#
Map字典中的关键字
NaN
与数据框中的NaN
值不匹配。我已修改了字典中的关键字。