I have a dataframe with a column that contain strings. I want to know if it is possible to create a new column based on the dataframe. This is an example of the column:
col1
016e3d588c
071b4x718g
011e3d598c
041e0i608g
I want to create a new column based on the last character of the string. This is what I tried:
for i in DF['col1']:
if i[-1] == 'g':
DF['col2'] = 1
else:
DF['col2'] = 0
I want the new column like this:
col2
0
1
0
1
but my code have the following output:
col2
0
0
0
0
Is possible to do it?
Thanks in advance