"'str' object is not callable" using DictVectorizer on a column of pandas dataframe

119 views Asked by At

I'm developing a machine learning project in which I need to predict the prices of hotel rooms.

Since in my data set there are also the names of the hotels, I want to improve the performance of my model by using DictVectorizer on the name feature.

However Python keeps presenting the "str' object is not callable" error at the line vec= dict.fit_transform(X_data). Can anyone help me with this?

The code is in the picture

1

There are 1 answers

1
Pran Pratim Gogoi On

For reference, I think the issue arises due to use of dtype='str' while initializing DictVectorizer(sparse=False,dtype='str'). Instead it should be specified as dtype=str without the quotes. str is not a callable object in python whereas str is a callable object.