Attribute Error :'list' object has no function 'lower'

146 Views Asked by At

how to apply the lower function for preprocessing of text i am using this line ``df['Sentences'] = df['Sentences'].apply(lambda x: x.lower() if type(x)==str else x)` but tfidf is giving error ('list' object has no attribute 'lower') TFIDF ERROR

1

There are 1 best solutions below

0
Rafi Patel On

Its a simple one try this, but it will convert all the values to str, regardless of its type.

`df['Sentences'] = df['Sentences'].str.lower()`

or if you want to do it with type check, using lambda it will be df['Sentences'] = df['Sentences'].apply(lambda x: str(x).lower() if type(x)==str else x)