My requirement is to convert the columns of a dataframe and concatenate them like below:
A B C D Target
1 2 321 1_2_321
2 35 123 2_35_123
3 55 123 3_55_123
4 33 4_33_END
5 11 123 5_11_123
I am able to achieve it using:
df['add'] = df['B'].astype('str') + '_' + df['C'].astype('str') + '_' + df['D'].astype('str')
but I don't know how to specify the 'END' string for the last. The current code output is coming like,
A B C D add
1 2 321 1_2_321
2 35 123 2_35_123
3 55 123 3_55_123
4 33 4_33_
5 11 123 5_11_123
Is there any thing I missed out ? anything to learn ?
df.iloc[-1,-1] += 'END'?df.tail(1)['Target'] += 'END'?df['D'] = df['D'].fillna('END')?