您可以
str.contains用来掩盖包含“
ball”的行,然后用新值覆盖:
In [71]:df.loc[df['sport'].str.contains('ball'), 'sport'] = 'ball sport'dfOut[71]: name sport0 Bob tennis1 Jane ball sport2 Alice ball sport
要使其不区分大小写,请通过`case = False:
df.loc[df['sport'].str.contains('ball', case=False), 'sport'] = 'ball sport'
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)