我有一个非常大的数据集,我想用数字替换字符串。我想在不为数据集中的每个键(列)键入映射函数的情况下对数据集进行操作。(类似于 fillna 方法,但将特定字符串替换为关联值)。有没有办法做到这一点?
这是我的数据集的示例
data
resp A B C
0 1 poor poor good
1 2 good poor good
2 3 very good very good very good
3 4 bad poor bad
4 5 very bad very bad very bad
5 6 poor good very bad
6 7 good good good
7 8 very good very good very good
8 9 bad bad very bad
9 10 very bad very bad very bad
期望的结果:
data
resp A B C
0 1 3 3 4
1 2 4 3 4
2 3 5 5 5
3 4 2 3 2
4 5 1 1 1
5 6 3 4 1
6 7 4 4 4
7 8 5 5 5
8 9 2 2 1
9 10 1 1 1
非常差=1,差=2,差=3,好=4,非常好=5
//乔纳斯