Skip to content
Advertisement

Python Dataframe For loop (if i.contains)

I need a for loop on a column specific. With this for loop, I will assign the value ‘Normal’ to a list if the column contains ‘Themes’. But I don’t know how to write it here. I would be glad if you help. Thanks in advance :) Dataset

For loops that I try

Advertisement

Answer

You can use np.where which is basically an if-else statement:

df['group'] = np.where(df['Developer ID'].str.contains('Themes'), 'Normal', 'Premium')
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement