Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/293.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何替换熊猫系列中非唯一索引中的值?_Python_Pandas - Fatal编程技术网

Python 如何替换熊猫系列中非唯一索引中的值?

Python 如何替换熊猫系列中非唯一索引中的值?,python,pandas,Python,Pandas,在图中,我想更改索引“Kelly”的值“哲学”,但我无法更改该值。使用set_value方法。使用带有布尔值列表的“.loc”访问器。 首先构建布尔值列表。 你想要的是索引=='Kelly'和值=='Philosophy' bool_list = (all_students_classes.index == 'Kelly') & (all_students_classes == 'Philosophy') 然后将此布尔值列表传递给“.loc”访问器并分配一个新值 all_student

在图中,我想更改索引“Kelly”的值“哲学”,但我无法更改该值。使用set_value方法。

使用带有布尔值列表的“.loc”访问器。 首先构建布尔值列表。 你想要的是索引=='Kelly'和值=='Philosophy'

bool_list = (all_students_classes.index == 'Kelly') & (all_students_classes == 'Philosophy')
然后将此布尔值列表传递给“.loc”访问器并分配一个新值

all_student_classes[bool_list] = 'Not Philosophy'

请以代码的形式发布代码,而不是图像。并发布一个可复制的示例()。