You can find out the sentiment of each tweet using the textblob library and analyze the distribution of positivity/negativity.
Creating Sample Tweets
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import pandas as pd Sample_Tweets=pd.DataFrame(columns=['Tweets'],data=['RT @saraspilot: At a time when the country has crossed 3.5 million corona virus cases, even the Health minister after months has realised n…', "RT @scotchism: The number of dislikes on Modiji's video is rising like Corona virus cases now. \n\nIT CELL SHOULD WORK HARD TO FLATTEN THE CU…", "RT @sharmavishesh26: I don't know what we used to talk about before Corona virus.", 'The way he lies, is much more dangerous than Corona Virus #मोदीजी_के_झूठ https://t.co/pIT5yaDJwt', "The number of dislikes on Modiji's video is rising like Corona virus cases now. \n\nIT CELL SHOULD WORK HARD TO FLATTEN THE CURVE.", '@AAP4Jharkhand @AamAadmiParty @ArvindKejriwal @AAPRajasthan @AAPTELANGANA @aartic02 @AAPChhattisgarh @AAPUttarPradesh @AAPUttarakhand Photo me chehra dikhane ke chakkar me shriman mask lagane ka sahi Tarika bhool gaye. With this attitude these people will be contributing in spreading of virus. How it will help in identifying Corona? Is it substitute for Corona test?', "@FIDE_chess @MatchTV @rsportru @the_hindu @htTweets @DainikBhaskar @sportexpress @airnewsalerts We'll win the battle of Corona Virus as well....in the same way...\n🇮🇳🤝🇷🇺", 'Indians do not fear #Corona any more. Or so it seems. Slowly precautions are going out of the window. I see so many people heading to crowded places. Social distancing is reducing by the day. What gives people so much confidence against the virus?\n#coronainindia #coronavirus', '@JavedKhan_IND @SureshChavhanke @Amul_Coop Here corona virus spreads on Ram Navami\n\n* Here corona virus spreads on Krishna Janmashtami\n\n* Here corona virus spreads on Ganesh Chaturthi\n\nBut on Muharram procession, Corona virus will hide in fear! https://t.co/9viQcskudv', '🙏 At the request of Shahdara Bar Association, 600 lawyers and staff distributed homeopathy medicines to increase the immunity approved by Ministry of AYUSH to prevent corona virus.\n\nDr.Dc Prajapati https://t.co/UlYAz7O8UY'] ) Sample_Tweets |
Sample Output

Finding sentiments using textblob
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
# Sentiment Analysis using textblob from textblob import TextBlob def get_sentiment(inpText): SentimentScore=TextBlob(inpText).sentiment[0] Sentiment='' if(SentimentScore > 0.1): Sentiment='Positive' elif(SentimentScore < -0.1): Sentiment='Negative' else: Sentiment='Neutral' return(Sentiment) ############################################# # Using the defined function to get sentiments for each tweet Sample_Tweets['Sentiment']=Sample_Tweets['Tweets'].apply(get_sentiment) Sample_Tweets |
Sample Output

Visualizing the sentiments
1 2 3 4 5 6 7 8 9 10 11 12 |
# Visualizing the overall sentiment distribution %matplotlib inline import matplotlib.pyplot as plt fig, subPlot =plt.subplots(nrows=1, ncols=2, figsize=(10,4)) fig.suptitle("Sentiment analysis of Tweets") # Grouping the data GroupedData=Sample_Tweets.groupby('Sentiment').size() # Creating the charts GroupedData.plot(kind='bar', ax=subPlot[0], color=['crimson', 'lightblue','yellowgreen']) GroupedData.plot(kind='pie', ax=subPlot[1], colors=['crimson', 'lightblue','yellowgreen']) |
Sample Output

Author Details
Lead Data Scientist
Farukh is an innovator in solving industry problems using Artificial intelligence. His expertise is backed with 10 years of industry experience. Being a senior data scientist he is responsible for designing the AI/ML solution to provide maximum gains for the clients. As a thought leader, his focus is on solving the key business problems of the CPG Industry. He has worked across different domains like Telecom, Insurance, and Logistics. He has worked with global tech leaders including Infosys, IBM, and Persistent systems. His passion to teach inspired him to create this website!