# How to add a new column with labels in a dataframe?

I have thousands of sentences that I would need to label based on their sentiment. An example is

Testo
"Può dirmi quale fotocamera della Sony fa delle belle foto?"
"Che macchina fantastica! Ha smesso di funzionare dopo due giorni"
"Quel pallavolista ha un fisico pauroso"


I have tried using Fasttext (Python Package) but I do not know how to add the sentiment label in a new column. Also, I got the wrong sentiment (below it is shown the expected output).

Testo                                                            Sentiment
"Può dirmi quale fotocamera della Sony fa delle belle foto?"         0
"Che macchina fantastica! Ha smesso di funzionare dopo due giorni"  -1
"Quel pallavolista ha un fisico pauroso"                             1


How can I do it?

• Do you already have a trained model to classify sentiment? Jun 4 '20 at 15:40

Do you have a working method to get the sentiment label for an individual sentence?

If so, I would think you could just create a method to get the sentiment given a sentence and use it's return value as the row entry.

The apply function from pandas will apply a function to every row if you specify axis=1

def getSentiment(row):
# Do some sentiment operations here on row['Testo']
return sentiment_label

df.apply(getSentiment, axis=1)

• thank you @Sean Payne. May I ask you if you suggest to get the sentiment building some rules from scratch or just using some already existing tool in python (what you should suggest)?
– LdM
Jun 4 '20 at 23:15
• I'm not as sure about the sentiment labeling. I'm guessing there has been a ton done in that field though as the Twitter sentiment labeling is a popular beginner exercise, so consider doing some more Google searching to look for an existing method. Jun 5 '20 at 0:33