0

I need to take specific text from Column A and based on it, I need to create a new column and add values to it.

Device_users
Old_Android_user
New_Android_user
Old_IOS_user

Say I have the above column, I want to use it to create a new column:

Device_users Fan
Old_Android_user Google_fan
New_Android_user Google_fan
Old_IOS_user Apple_fan

So if there's 'Android' in column A then the new column should return 'Google_fan' or 'IOS', then 'Apple_fan'. Plus the new column created should have the title 'Fan'

1 Answer 1

1

Try with str.contains

df['Fan'] = np.where(df.Device_users.str.contains('Android'),'Google_fan','Apple_fan')
df
Out[13]: 
       Device_users         Fan
0  Old_Android_user  Google_fan
1  New_Android_user  Google_fan
2      Old_IOS_user   Apple_fan
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.