回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>有人知道我可以用什么代码来代替下面的代码吗?我可以使用“startswith”而不是单独的where子句吗?我该怎么做</p>
<pre><code>ds_4['New_Domain'] = np.where(ds_4['Domain'] == 'Alcohol,animals,children,crime', 'Alcohol', ds_4.Domain)
ds_4['New_Domain'] = np.where(ds_4['Domain'] == 'Alcohol,campaign-finance,ethics,public-service', 'Alcohol', ds_4.New_Domain)
ds_4['New_Domain'] = np.where(ds_4['Domain'] == 'Alcohol,candidates-biography', 'Alcohol', ds_4.New_Domain)
ds_4['New_Domain'] = np.where(ds_4['Domain'] == 'Alcohol,candidates-biography,crime', 'Alcohol', ds_4.New_Domain)
ds_4['New_Domain'] = np.where(ds_4['Domain'] == 'Alcohol,children', 'Alcohol', ds_4.New_Domain)
ds_4['New_Domain'] = np.where(ds_4['Domain'] == 'Alcohol,children,crime,public-health,public-safety', 'Alcohol', ds_4.New_Domain)
</code></pre>