Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

I want the column to return 'Consider' if a comment column contains a string 'True_Critical' otherwise return the 'Not Consider'.

Comment                                            Result

True_Critical_Alarm - Confirmed with DB            Consider

True_Critical  - Confirmed with DBM                Conisder

True_Normal- Confirmed with DB                     Not Conisder  

I used df['cosider']=df['Comment '].str.startswith('True_critical') but it is not work.

1 Answer

0 votes
by (36.8k points)

Use the numpy.where to fill in values in your Result column:

df['Result'] = np.where(df['Comment'].str.startswith('True_Critical'), 'Consider', 'Not Consider')

It allows you to substitute True and False values with values of your choice.

Improve your knowledge in data science from scratch using Data science online courses

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...