Dismiss
Announcing Stack Overflow Documentation

We started with Q&A. Technical documentation is next, and we need your help.

Whether you're a beginner or an experienced developer, you can contribute.

Sign up and start helping → Learn more about Documentation →

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'
share|improve this question

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(' ')
share|improve this answer
    
How do i achieve what i want to achieve then. Thanks – aceminer Jun 12 at 3:51
    
does that work for you? @aceminer – michael_j_ward Jun 12 at 3:58
    
Not really. Got an error: "expected a character buffer object" – aceminer Jun 12 at 3:58
    
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 – michael_j_ward Jun 12 at 4:04

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.