Pandas code running but not doing anything

87 Views Asked by At

Below is the code:

import pandas as pd

from nltk.sentiment.vader import SentimentIntensityAnalyzer

dataset=pd.read_excel('file_path')

sia=SentimentIntensityAnalyzer()

dataset['polarity scores']=dataset['column_title'].apply(lambda x: sia.polarity_scores(str(x))['compound'])

print("done")

I would like it to take the excel file named/located file_path and give me polarity scores for the text in the column entitled column title but I'm not sure what I'm doing wrong.The code runs without any errors but it does not edit the excel file at all

1

There are 1 best solutions below

0
On

You forgot to save your file

use dataset.to_excel('output_file_path.xlsx') to save your file

import pandas as pd
from nltk.sentiment.vader import SentimentIntensityAnalyzer

dataset=pd.read_excel('file_path')

sia=SentimentIntensityAnalyzer()

dataset['polarity scores']=dataset['column_title'].apply(lambda x: sia.polarity_scores(str(x))['compound'])

dataset.to_excel('output_file_path.xlsx', index = False) # save file

print("done")