0

I am extremely new to numpy.

Just wondering why does this not work.

print items['description'] 

Yields

0                            Продам Камаз 6520 20 тонн
1                                      Весь в тюнинге.
2    Телефон в хорошем состоянии, трещин и сколов н...
3    Отличный подарок на новый год от "китайской ap...
4        Лыжные ботинки в хорошем состоянии, 34 размер
Name: description, dtype: object

Trying to apply this method to all the rows in this col.

items['description'] = vectorize_sentence(items['description'].astype(str))

This is the function definition for vectorize sentence.

def vectorize_sentence(self, sentence):
    # Tokenize 
    print 'sentence', sentence

    tkns = self._tokenize(sentence)
    vec = None
    for tkn in tkns: 
        print 'tkn', tkn.decode('utf-8')
        print type(tkn)
        if self.model[tkn.decode('utf-8')]:
            vec = sum(vec, self.model[tkn.decode('utf-8')])
    #vec = sum([self.model[x] for x in tkns if x in self.model])
    #print vec
def _tokenize(self, sentence):
    return sentence.split(' ')

Error Message:

AttributeError: 'Series' object has no attribute 'split'

1 Answer 1

1

Your getting that error because 'Series' object has no attribute 'split'. Mainly, the .astype(str) does not return a single long string like you think it does

items = pd.DataFrame({'description': ['bob loblaw', 'john wayne', 'lady gaga loves to sing']})
sentence = items['description'].astype(str)
sentence.split(' ')

now try

sentence = ' '.join(x for x in items['description'])
sentence.split(' ')

and then implementing in your function

def _tokenize(self, sentence):
    return ' '.join(x for x in items['description']).split(' ')
Sign up to request clarification or add additional context in comments.

3 Comments

How do i achieve what i want to achieve then. Thanks
Not really. Got an error: "expected a character buffer object"
Well that is probably when you are writing to a file see this stackoverflow question. In any case, it certainly is not related to this question, so please mark this one as closed and post a new question with more details if need be

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.