由于其长度大小,我想更新特定的行值(在数据帧中多次出现(。
这是我的示例数据集,包含两列。
metro_regional status
Metro Referred
Regional Referred
Metro Referred
Regional Referred
Metro Referred
Regional <img src="/resource/status_icons/status-new.png" alt=" " style="height:22px; width:22px;" border="0"/> New
Metro <img src="/resource/status_icons/status-new.png" alt=" " style="height:22px; width:22px;" border="0"/> New
Metro <img src="/resource/status_icons/status-new.png" alt=" " style="height:22px; width:22px;" border="0"/> New
Regional <img src="/resource/status_icons/status-new.png" alt=" " style="height:22px; width:22px;" border="0"/> New
Metro <img src="/resource/status_icons/status-new.png" alt=" " style="height:22px; width:22px;" border="0"/> New
从上面的数据集中,我想将行值<img src="/resource/status_icons/status-new.png" alt=" " style="height:22px; width:22px;" border="0"/> New
更新为Others
期望输出;
metro_regional status
Metro Referred
Regional Referred
Metro Referred
Regional Referred
Metro Referred
Regional Others
Metro Others
Metro Others
Regional Others
Metro Others
如何用特定的行值更新多个行值?
如有任何帮助,我们将不胜感激。
您可以将其分配给
str = '<img src="/resource/status_icons/status-new.png" alt=" " style="height:22px; width:22px;" border="0"/> New'
df.loc[df['status'].eq(str),'status'] = 'other'
您可以使用.loc
来更新满足条件的特定列。
other_status = '<img src="/resource/status_icons/status-new.png" alt=" " style="height:22px; width:22px;" border="0"/> New'
df.loc[df.status == other_status, 'status'] = 'Others'