TransWikia.com

The result obtained from pandas series operation cannot get assigned to a variable

Stack Overflow Asked by San22 on November 24, 2021

I am using IMDB reviews dataset containing two columns – sentiment and review. I am trying to convert the review column to a list so as to perform loop operations but when I assign my series(review column) to a variable and print the variable, the output shows nothing. When I separately print df['review'].values.tolist() without assigning to any variable, it correctly outputs a list.

One Answer

I can't reproduce your problem but you can probably solve it simply by improving your code.

  1. Make a function that parse one sentence
  2. Apply this function to all elements in the column review

Basically, your code should look like this:

def parse_sentence(sentence):
    sentence = sentence.lower()
    sentence = re.sub(pattern, '', sentence)
    ...
    return sentence

clean_reviews = df["review"].map(parse_sentence)
print(clean_review)

Answered by qmeeus on November 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP