Python | TextBlob.sentiment() method (original) (raw)

Last Updated : 26 Jul, 2025

Sentiment analysis helps us find the emotional tone of text whether it’s positive, negative or neutral. The **TextBlob.sentiment() method simplifies this task by providing two key components:

Let's see a basic example:

Python `

from textblob import TextBlob

text = "GFG is a good company and always value their employees." blob = TextBlob(text) sentiment = blob.sentiment print(sentiment)

`

**Output:

Sentiment(polarity=0.7, subjectivity=0.6000000000000001)

**Syntax:

TextBlob.sentiment

Return:

Lets see some more examples:

Example 1: Negative Sentiment

Here, we analyze a sentence that expresses a strong negative sentiment. The polarity score reflects the negative tone while the subjectivity shows opinion-based statement.

Python `

text = "I hate bugs in my code." blob = TextBlob(text) sentiment = blob.sentiment print(sentiment)

`

**Output:

Sentiment(polarity=-0.8, subjectivity=0.9)

Example 2: Neutral Sentiment

In this example, we’ll analyze a neutral sentence that conveys factual information without expressing any strong opinion or emotion. It will show how TextBlob classifies a sentence with no sentiment bias.

Python `

text = "The sun rises in the east." blob = TextBlob(text) sentiment = blob.sentiment print(sentiment)

`

**Output:

Sentiment(polarity=0.0, subjectivity=0.0)

Example 3: Mixed Sentiment

Here the sentence presents a neutral sentiment but is more opinion-based than factual. The polarity score remains neutral while the subjectivity score reflects an opinion or preference.

Python `

text = "I enjoy coding, but debugging can be frustrating." blob = TextBlob(text) sentiment = blob.sentiment print(sentiment)

`

**Output:

Sentiment(polarity=0.0, subjectivity=0.7)

Practical Use Cases

This can be useful in various applications including:

  1. **Social Media Monitoring: Analyze sentiment in social media posts to identify public opinion, tracking how positive or negative people feel about topics. This helps in understanding overall sentiment toward trends or events.
  2. **Customer Feedback: Quickly assess customer reviews to identify satisfaction levels, detecting trends in product or service reception. It allows businesses to find customer satisfaction in real-time.
  3. **Content Moderation: Identify and flag negative or inappropriate comments, helping maintain a positive environment in online communities. This improves user experience and promotes healthy discussions.

Limitations

  1. **Context Issues: TextBlob struggles with sarcasm or irony, leading to inaccurate sentiment scores and it may miss the true sentiment of a message. This affects its reliability in certain contexts.
  2. **Simplicity: It relies on a basic lexicon which may miss deeper nuances, making it less accurate for complex or nuanced text. This can limit its application for sophisticated analysis.
  3. **Ambiguity: Mixed sentiments in one sentence can be difficult for it to handle which may result in incorrect classification of sentiment. This reduces its effectiveness in certain cases.