我正在学习一个熊猫教程,该教程显示通过将字典传递给series.map方法来替换列中的值。V The Empire Strikes Back":True, NaN:False star_wars[c] = star_wars[c].map(answers)
我得到了NameError: name 'N
假设我有一个pandas数据帧,如下所示:col1 col2 0 A A60 1 B B23 2 C NaN数据是从csv文件中读取的。假设我想要将“col2”的每个非缺失值更改为其前缀(即'A‘或'B')。在不编写for循环的情况下,我如何做到这一点?预期输出为col1 col2 0 A A 1 B B 2 C NaN