I have a text file and 2 user defined positive and negative files. I'am comparing the words present the 2 files with the text file, and returning either positive or negative.
But i need to print those keywords in the text, which categorized them to either positive or negative.
example of the output i looking for:
file_name IBM Keywords Label
audio1.wav The customer is good good Positive
audio2.wav the service is bad bad Negative
Please let me know how to go about it. Here's the code so far
pos = readwords('C:\\Users\\anagha\\Desktop\\SynehackData\\positive.txt')
neg = readwords('C:\\Users\\anagha\\Desktop\\SynehackData\\Negative.txt')
pos = [w.lower() for w in pos]
neg = [w.lower() for w in neg]
def assign_comments_labels(x):
try:
if any(w in x for w in pos) :
return 'positive'
elif any(w in x for w in neg):
return 'negative'
else:
return 'neutral'
except:
return 'neutral'
import pandas as pd
df = pd.read_csv("C:\\Users\\anagha\\Desktop\\SynehackData\\noise_free_audio\\outputfile.csv", encoding="utf-8")
df['IBM'] = df['IBM'].str.lower()
df['file_name'] = df['file_name'].str.lower()
df['labels'] = df['IBM'].apply(lambda x: assign_comments_labels(x))
df[['file_name','IBM','labels']]