小编Arj*_*sai的帖子

如何用字典值替换Pandas系列

我想将我的字典值链接到pandas系列对象。我已经尝试过replace方法和map方法仍然没有运气。

按照链接: 用字典替换pandas系列中的值

仍然无法正常工作,我的示例熊猫看起来像:

index                    column
0                      ESL Literacy
1    Civics  Government Team Sports
2      Health  Wellness Team Sports
3              Literacy Mathematics
4                       Mathematics
Run Code Online (Sandbox Code Playgroud)

字典:

{'civics': 6,
 'esl': 5,
 'government': 7,
 'health': 8,
 'literacy': 1,
 'mathematics': 4,
 'sports': 3,
 'team': 2,
 'wellness': 9}
Run Code Online (Sandbox Code Playgroud)

所需输出:

0 [5,1]
1 [6,7,2,3]
2 [8,9,2,3]
3 [1,4]
4 [4]
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激。谢谢 :)

python dictionary pandas

4
推荐指数
1
解决办法
64
查看次数

标签 统计

dictionary ×1

pandas ×1

python ×1