If-else conditional assignment in pandas If-else conditional assignment in pandas pandas pandas

If-else conditional assignment in pandas


You can use numpy.where():

import numpy as nporiginal["new"] = np.where(original["col"].isin(["b", "x"]), 1, 99)print(original)#  col  new#0   a   99#1   b    1#2   c   99