The objective is to assign a value to the column EXPECTED T. The value to be assigned is C1 S + C2 B if there is EM in column C2 B, else the value is image of the value at C2 B.
To realise the objective, the following code is propose
data = {'C1 S': ['AB','AB','CD','CD','CD'],
'C2 B': ['EM','EM','EM','F','F'],
'EXPECTED_OUTPUT': ['AB EM','EB EM', 'CD EM','F','F']}
df = pd.DataFrame(data)
df['EXPECTED T']=df['C1 S']+' '+ df['C2 B']
mask = df ['C2 B'].str.contains ( r'EM', na=True )
df.loc [~mask, 'EXPECTED T'] = df.loc [~mask, 'C2 B']
But, I wonder if there is more Pythonic of achieving similar result then the above code?