Home > Mobile >  String object has no attribute 'str'
String object has no attribute 'str'

Time:12-01

I'm getting following error: Error snip

Can someone please guide what needs to be done to fix the error?

The following code snippet has purpose to check whether a particular word is present in a string.

x= 'this string is supposed to contain windows' np.where(x.str.contains('windows'),'Windows','Non Windows')

CodePudding user response:

x is a string, and so you are saying str.str. Im guessing you copied and paster from a tutorial, but your code should look like this:

x='this string is supposed to contain windows' 
np.where(x.contains('windows'),'Windows','Non Windows')

This should work.

CodePudding user response:

You don't need the .str there as x is already a string you can just use.

x.contains('windows')
  • Related