Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在索引DataFrame 列中的单元格子集,并尝试将布尔值分配True给所述子集:
True
df['mycolumn'][df['myothercolumn'] == val][idx: idx + 25] = True
但是,当我 slice 时df['mycolumn'][df['myothercolumn'] == val][idx: idx + 25],仍然可以找到我的初始值。换句话说,未应用更改!
df['mycolumn'][df['myothercolumn'] == val][idx: idx + 25]
我要扯掉我的头发了。我究竟做错了什么?
试试这个:
df.loc[df['myothercolumn']==val, some_column_name] = True
some_column_name应该是您要添加或更改的列的名称。
some_column_name