I'm struggling to create a new col in a df based on an existing column using a condition. Essentially if the Client Contract Number contains an underscore, I want the value in the new column to be all characters before the underscore, otherwise I want it to be the Client Contract Number with all dashes removed. I'm able to remove the dashes with the below, but the second line doesn't work
raw_data_df['Search Text'] = raw_data_df['Client Contract Number'].str.replace('-','')raw_data_df['Search Text'] = raw_data_df['Client Contract Number'].str.split('_')[0] if raw_data_df['Client Contract Number'].str.contains("_") else raw_data_df['Client Contract Number'].str.replace('-','')