shivesh kumar
shivesh kumar

Reputation: 85

AttributeError: 'NoneType' object has no attribute 'lower

I am trying to implement CountVectorizer on a tags data but everytime it throws attribute error , tried everything and still cant understand why this error. This is my code,

vectorizer = CountVectorizer(tokenizer = lambda x: x.split(" "))

tag_dtm = vectorizer.fit_transform(tag_data['Tags'])

and this is the error i get:

`AttributeError                            
Traceback (most recent call last)
<ipython-input-53-7a05ab3b6655> in <module>()

      7 # and learns the vocabulary; second, it transforms our training data
      8 # into feature vectors. The input to fit_transform should be a list of strings.                  
 ----> 9 tag_dtm = vectorizer.fit_transform(tag_data['Tags'])


3 frames


/usr/local/lib/python3.6/dist-packages/sklearn/feature_extraction/text.py in _preprocess(doc, accent_function, lower)
     
     66     """
      
     67     if lower:

     ---> 68         doc = doc.lower()
     
     69     if accent_function is not None:

     70         doc = accent_function(doc)

AttributeError: 'NoneType' object has no attribute 'lower'`

Upvotes: 2

Views: 3292

Answers (3)

Sarim Sikander
Sarim Sikander

Reputation: 406

You can complete the code by the following syntax and eliminate if any value is taking null by list comprehension.

tag_dtm = vectorizer.fit_transform([str(val) for val in tag_data['Tags'] if val is not np.nan])

Do let me know if this works for you!

Upvotes: 5

Osayanhu Imoisili
Osayanhu Imoisili

Reputation: 1

Try and convert it to a string as lower is a string function and since one of the data passed into the CountVectorizer is a NoneType, It literally hooks there

Upvotes: 0

Shashi123
Shashi123

Reputation: 159

'doc' is not containing any data/string in it, it is None type . None is not the meaning of none or blank , its a type. check that with a condition like "if doc is None:" it will be true there.

Upvotes: 0

Related Questions