{"id":46653,"date":"2021-07-01T00:00:00","date_gmt":"2021-07-01T07:00:00","guid":{"rendered":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/"},"modified":"2025-11-13T12:55:26","modified_gmt":"2025-11-13T20:55:26","slug":"twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2","status":"publish","type":"post","link":"https:\/\/www.griddb.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/","title":{"rendered":"Twitter Sentiment Analysis with GridDB &#8211; Visualization of Sentiment Data (part-2)"},"content":{"rendered":"<p><strong>Introduction<\/strong><\/p>\n<p>In the part-1 of the blog, we implemented GridDB python script to save and retrieve the Twitter data. In this blog, we will continue with the sentiment analysis and visualization of the sentiment data. We will calculate the sentiment values for each and every tweet, store the sentiment values, and visualize them to draw useful insights for the popular fashion brands. Furthermore, we will also implement some data science algorithms like Hierarchical Cluster and visualize it using Dendrograms. In the end, we will use the python folium library to visualize the positive and negative teets geographically which will helps the fashion brands to target a particular geographical for efficient market growth.<\/p>\n<p><strong>Prerequisites<\/strong><\/p>\n<p>We will use Python3 libraries like Textblob to calculate the quantitative values for the polarity and subjectivity of each and every tweet text. Also, we will use matplotlib and folium as charting tools for sentiment visualization. We will use scipy library for performing hierarchical clustering on the sentiment dataset.<\/p>\n<p><strong>Data Structure Schema<\/strong><\/p>\n<table border=\"1\">\n<thead>\n<tr>\n<th>\n        Field Name\n      <\/th>\n<th>\n        Data Type(GridDB)\n      <\/th>\n<th>\n        Notes\n      <\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\n        Serial No\n      <\/td>\n<td>\n        INTEGER\n      <\/td>\n<td>\n      <\/td>\n<\/tr>\n<tr>\n<td>\n        Screen Name\n      <\/td>\n<td>\n        STRING\n      <\/td>\n<td>\n        Twitter Author Name\n      <\/td>\n<\/tr>\n<tr>\n<td>\n        Twitter ID\n      <\/td>\n<td>\n        STRING\n      <\/td>\n<td>\n        Twitter handle\n      <\/td>\n<\/tr>\n<tr>\n<td>\n        Tweet\n      <\/td>\n<td>\n        STRING\n      <\/td>\n<td>\n        Tweet text\n      <\/td>\n<\/tr>\n<tr>\n<td>\n        Date\n      <\/td>\n<td>\n        STRING\n      <\/td>\n<td>\n      <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>In the part-1 of the blog, we implemented GridDB containers to save and fetch the Twitter data. The retrieved tweet data is stored in a data frame variable as follows.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\"># Define the container names\ntweet_dataaset_container = excel_sheet_name\n# Get the containers\ntweet_data = gridstore.get_container(tweet_dataaset_container)\n\n# Fetch all rows - tweet_container\nquery = tweet_data.query(\"select *\")\nrs = query.fetch(False)\nprint(f\"{tweet_dataaset_container} Data\")\n\n# Iterate and create a list\nretrieved_data = []\nwhile rs.has_next():\n   data = rs.next()\n   retrieved_data.append(data)\n\nprint(retrieved_data)\n\n# Convert the list to a pandas data frame\ntweet_dataframe = pd.DataFrame(retrieved_data,\n                                 columns=['sno', 'twitter_name', 'twitter_id', 'tweet', 'date'])\n\n# Get the data frame details\nprint(tweet_dataframe)\ntweet_dataframe.info()<\/code><\/pre>\n<\/div>\n<p>We will continue to find the sentiment score first, and then later visualize the data for sentiment analytics.<\/p>\n<p><strong>Showing Tweets data as WordClouds<\/strong><\/p>\n<p>We can have an overview of the popular keywords which are used frequently during tweet mining for fashion brands. For this, we implement word cloud on the entire dataset.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">from wordcloud import WordCloud, STOPWORDS\nimport matplotlib.pyplot as plt\nstopwords = set(STOPWORDS)\n\ndef show_wordcloud(data, title = None):\n    wordcloud = WordCloud(\n        background_color='white',\n        stopwords=stopwords,\n        max_words=200,\n        max_font_size=40, \n        scale=3,\n        random_state=1 # chosen at random by flipping a coin; it was heads\n    ).generate(str(data))\n\n    fig = plt.figure(1, figsize=(12, 12))\n    plt.axis('off')\n    if title: \n        fig.suptitle(title, fontsize=20)\n        fig.subplots_adjust(top=2.3)\n\n    plt.imshow(wordcloud)\n    plt.show()\n\nshow_wordcloud(tweet_dataframe)<\/code><\/pre>\n<\/div>\n<p>The equivalent WordCloud for the entire dataset contains important keywords like Worker Safety, Supply Chain Disaster, Bangladeshi Worker, etc.<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image1.png\"><img fetchpriority=\"high\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image1.png\" alt=\"\" width=\"1728\" height=\"1086\" class=\"aligncenter size-full wp-image-27604\" srcset=\"\/wp-content\/uploads\/2021\/06\/image1.png 1728w, \/wp-content\/uploads\/2021\/06\/image1-300x189.png 300w, \/wp-content\/uploads\/2021\/06\/image1-1024x644.png 1024w, \/wp-content\/uploads\/2021\/06\/image1-768x483.png 768w, \/wp-content\/uploads\/2021\/06\/image1-1536x965.png 1536w, \/wp-content\/uploads\/2021\/06\/image1-600x377.png 600w\" sizes=\"(max-width: 1728px) 100vw, 1728px\" \/><\/a><\/p>\n<p><strong>Calculating Sentiment Values of Tweet Dataset<\/strong><\/p>\n<p>The polarity and subjectivity values of the tweets depend upon the individual lexicons of the tweet stated. The final sentiment score is the sum of the sentiment value of all lexicons present in the tweet. Textblob is a python library that works on the similar above logic and returns the numerical sentiment value of tweets. Let us calculate the sentiment values using textblob by iterating through each tweet.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">from textblob import TextBlob  # For getting the quantitative value for the polarity and subjectivity\n\nimport re  # For the calculation of regular expressions\n\n# a function to clean the tweets using regualr expression\ndef clean_tweet(tweet):\n    '''\n    Utility function to clean the text in a tweet by removing\n    links and special characters using regex.\n    '''\n    return ' '.join(re.sub(\"(@[A-Za-z0-9]+)|([^0-9A-Za-z  t])|(w+:\/\/S+)\", \" \", tweet).split())\n\n\nfor tweet in tweets:\n        analysis = TextBlob(clean_tweet(tweet))\n        pol = analysis.sentiment.polarity\n        sub = analysis.subjectivity\n        pol_round = '%.3f' % pol\n        sub_round = '%.3f' % sub<\/code><\/pre>\n<\/div>\n<p>In the above code snippet, we calculated the polarity and subjectivity values of tweets, after cleaning them. Please note that the polarity value is considered as the final sentiment of the score of that particular tweet though subjectivity value defines how well the tweet matches with the given context. We will continue the visualization of these polarity values using matplotlib.<\/p>\n<p><strong>Visualization of Sentiment Data using Matplotlib<\/strong><\/p>\n<p>Since we now have the numerical sentiment values of tweets, we can plot them using matplotlib to find the pattern from 2013-2018.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">import matplotlib.pyplot as plt  # For plotting the graphs and charts\n\n# plotting the line-chart for the average polarity with the supply-chain-incidents\nplt.title(\"Average Sentiment for Fashion Supply Chain\")\nplt.xlabel(\"Year\")\nplt.ylabel(\"Average Yearly Sentiment Score\")\nplt.ylim(-0.3, 0.3)\nplt.plot(list_sheetnames, average_polarity_sheets)\nplt.show()<\/code><\/pre>\n<\/div>\n<p>The line chart for the above code snippet shows the sentiment values with the respective year.<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image2.png\"><img decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image2.png\" alt=\"\" width=\"2308\" height=\"1312\" class=\"aligncenter size-full wp-image-27605\" srcset=\"\/wp-content\/uploads\/2021\/06\/image2.png 2308w, \/wp-content\/uploads\/2021\/06\/image2-300x171.png 300w, \/wp-content\/uploads\/2021\/06\/image2-1024x582.png 1024w, \/wp-content\/uploads\/2021\/06\/image2-768x437.png 768w, \/wp-content\/uploads\/2021\/06\/image2-1536x873.png 1536w, \/wp-content\/uploads\/2021\/06\/image2-2048x1164.png 2048w, \/wp-content\/uploads\/2021\/06\/image2-150x85.png 150w, \/wp-content\/uploads\/2021\/06\/image2-600x341.png 600w\" sizes=\"(max-width: 2308px) 100vw, 2308px\" \/><\/a><\/p>\n<p>We have also implemented the matplotlib library to visualize the sentiment values exclusively for each of the fashion brands. Using the above code snippet for matplotlib line-chart, we got the sentiment positive trend for brands like Zara and Gap.<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image3.png\"><img decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image3.png\" alt=\"\" width=\"1376\" height=\"1030\" class=\"aligncenter size-full wp-image-27606\" srcset=\"\/wp-content\/uploads\/2021\/06\/image3.png 1376w, \/wp-content\/uploads\/2021\/06\/image3-300x225.png 300w, \/wp-content\/uploads\/2021\/06\/image3-1024x767.png 1024w, \/wp-content\/uploads\/2021\/06\/image3-768x575.png 768w, \/wp-content\/uploads\/2021\/06\/image3-600x449.png 600w\" sizes=\"(max-width: 1376px) 100vw, 1376px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image4.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image4.png\" alt=\"\" width=\"1376\" height=\"1072\" class=\"aligncenter size-full wp-image-27607\" srcset=\"\/wp-content\/uploads\/2021\/06\/image4.png 1376w, \/wp-content\/uploads\/2021\/06\/image4-300x234.png 300w, \/wp-content\/uploads\/2021\/06\/image4-1024x798.png 1024w, \/wp-content\/uploads\/2021\/06\/image4-768x598.png 768w, \/wp-content\/uploads\/2021\/06\/image4-600x467.png 600w\" sizes=\"(max-width: 1376px) 100vw, 1376px\" \/><\/a><\/p>\n<p>As we can analyze from the above sentiment line-charts, the sentiment of twitter customers of the fashion brands, has reacted positively or negatively in the given year.<\/p>\n<p><strong>Hierarchical Clustering and Dendrograms<\/strong><\/p>\n<p>To draw more analytics from the sentiment data, we can perform hierarchical clustering on the sentiment data values, and further plot the respective dendrograms. This will be useful from the data-science perspective to create clusters for the given tweet sentiment values. Let us first define our python function to draw a dendrogram from the given data.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">from scipy.cluster.hierarchy import cophenet  # used in hierarchical clustering\nfrom scipy.cluster.hierarchy import dendrogram, linkage  # used in making dendrograms\nfrom scipy.spatial.distance import pdist  # calculating the correlative distance\nfrom sklearn.cluster import MeanShift\n\n\ndef fancy_dendrogram(*args, **kwargs):\n    max_d = kwargs.pop('max_d', None)\n    if max_d and 'color_threshold' not in kwargs:\n        kwargs['color_threshold'] = max_d\n    annotate_above = kwargs.pop('annotate_above', 0)\n\n    ddata = dendrogram(*args, **kwargs)\n\n    if not kwargs.get('no_plot', False):\n        for i, d, c in zip(ddata['icoord'], ddata['dcoord'], ddata['color_list']):\n            x = 0.5 * sum(i[1:3])\n            y = d[1]\n            if y > annotate_above:\n                plt.plot(x, y, 'o', c=c)\n                plt.annotate(\"%.3g\" % y, (x, y), xytext=(0, -5),\n                             textcoords='offset points',\n                             va='top', ha='center')\n        if max_d:\n            plt.axhline(y=max_d, c='k')\n    return ddata<\/code><\/pre>\n<\/div>\n<p>The python script for the hierarchical clustering visualization using the matplotlib is given below.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\"> # performing heirarchical clustering on the each of the supply chain events\n    X = array(get_polarity_subjectivity_list(polarity, subjectivity))\n    ms = MeanShift()\n    ms.fit(X)\n    labels = ms.labels_\n    cluster_centers = ms.cluster_centers_\n    n_clusters_ = len(np.unique(labels))\n    # now saving it in the \"hierarchical_clustering_data.xls\" file\n    pol_x = (cluster_centers[0][0] + cluster_centers[1][\n        0]) \/ 2  # applying the coordinate geometry centre of two coordinates for the first two cluster points\n    sub_y = (cluster_centers[0][1] + cluster_centers[1][1]) \/ 2\n    ws2.write(i + 1, 0, i + 1)\n    ws2.write(i + 1, 1, list_sheetnames[i])\n    ws2.write(i + 1, 2, pol_x)\n    ws2.write(i + 1, 3, sub_y)\n    ws2.write(i + 1, 4, n_clusters_)\n    # writing all the cluster points\n    result_point = \"\"\n    for k in range(n_clusters_):\n        result_point = result_point + \" ( \" + str(round(cluster_centers[k][0], 3)) + \" , \" + str(\n            round(cluster_centers[k][1], 3)) + \" )\"\n\n    ws2.write(i + 1, 5, result_point)\n    # now plotting the hierarchical clustering with the cluster points\n    colors = 10 * ['r.', 'g.', 'b.', 'c.', 'k.', 'y.', 'm.']\n    for j in range(len(X)):\n        plt.plot(X[j][0], X[j][1], colors[labels[j]], markersize=10)\n\n    plt.scatter(cluster_centers[:, 0], cluster_centers[:, 1], marker='x', color='k', s=150, linewidths=5, zorder=10)\n    plt.title(list_sheetnames[i])\n    plt.xlabel(\"Polarity---------------------->\")\n    plt.ylabel(\"Subjectivity------------------>\")\n    plt.show()<\/code><\/pre>\n<\/div>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image5.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image5.png\" alt=\"\" width=\"2350\" height=\"1216\" class=\"aligncenter size-full wp-image-27608\" srcset=\"\/wp-content\/uploads\/2021\/06\/image5.png 2350w, \/wp-content\/uploads\/2021\/06\/image5-300x155.png 300w, \/wp-content\/uploads\/2021\/06\/image5-1024x530.png 1024w, \/wp-content\/uploads\/2021\/06\/image5-768x397.png 768w, \/wp-content\/uploads\/2021\/06\/image5-1536x795.png 1536w, \/wp-content\/uploads\/2021\/06\/image5-2048x1060.png 2048w, \/wp-content\/uploads\/2021\/06\/image5-600x310.png 600w\" sizes=\"(max-width: 2350px) 100vw, 2350px\" \/><\/a><\/p>\n<p>From the clustering chart, we can conclude that the sentiment values can be classified into 4 clusters, as per the sentiment polarity and subjectivity values.<br \/>\nNow we have the 4 clusters with their mean distance, we can feed it into the dendrograms function to plot the same.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\"> Y = pdist(score)\n    Z = linkage(Y, 'ward')\n    c, coph_dists = cophenet(Z, Y)  # c contains the coorelative distance for the clusters\n    # calculating the full dednrogram\n    plt.figure(figsize=(25, 10))\n    plt.title(\"Dendrogram : \" + list_sheetnames[i])\n    plt.xlabel('sample index')\n    plt.ylabel('distance')\n    fancy_dendrogram(\n        Z,\n        truncate_mode='lastp',\n        p=12,\n        leaf_rotation=90.,\n        leaf_font_size=12.,\n        show_contracted=True,\n        # annotate_above=10,\n        max_d=1.5\n    )\n    plt.show()<\/code><\/pre>\n<\/div>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image6.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image6.png\" alt=\"\" width=\"2138\" height=\"1318\" class=\"aligncenter size-full wp-image-27609\" srcset=\"\/wp-content\/uploads\/2021\/06\/image6.png 2138w, \/wp-content\/uploads\/2021\/06\/image6-300x185.png 300w, \/wp-content\/uploads\/2021\/06\/image6-1024x631.png 1024w, \/wp-content\/uploads\/2021\/06\/image6-768x473.png 768w, \/wp-content\/uploads\/2021\/06\/image6-1536x947.png 1536w, \/wp-content\/uploads\/2021\/06\/image6-2048x1263.png 2048w, \/wp-content\/uploads\/2021\/06\/image6-600x370.png 600w\" sizes=\"(max-width: 2138px) 100vw, 2138px\" \/><\/a><\/p>\n<p>Similarly, the dendrogram for Zara brand sentiment values can be calculated.<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image7.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image7.png\" alt=\"\" width=\"2162\" height=\"1264\" class=\"aligncenter size-full wp-image-27610\" srcset=\"\/wp-content\/uploads\/2021\/06\/image7.png 2162w, \/wp-content\/uploads\/2021\/06\/image7-300x175.png 300w, \/wp-content\/uploads\/2021\/06\/image7-1024x599.png 1024w, \/wp-content\/uploads\/2021\/06\/image7-768x449.png 768w, \/wp-content\/uploads\/2021\/06\/image7-1536x898.png 1536w, \/wp-content\/uploads\/2021\/06\/image7-2048x1197.png 2048w, \/wp-content\/uploads\/2021\/06\/image7-600x351.png 600w\" sizes=\"(max-width: 2162px) 100vw, 2162px\" \/><\/a><\/p>\n<p>Hence, we implemented the popular Hierarchical clustering on our twitter dataset and visualized it using dendrograms.<\/p>\n<p><strong>Geographical Visualization of Twitter Sentiment Data<\/strong><\/p>\n<p>To visualize the sentiment data geographically, we will use the python folium library to plot the geo-coordinates with the corresponding sentiment values.<\/p>\n<div class=\"clipboard\">\n<pre><code class=\"language-py\">import folium  # plotting the coordinates on the map\n\n# now making a data-frame with markers to show on the map\n    data = pd.DataFrame({\n        'lat': latitudes,\n        'lon': longitudes,\n        'name': places,\n        'sentiment': sentiments,\n    })\n    # now make an empty map\n    m = folium.Map(location=[20, 0], zoom_start=2)\n    # popup will be used when a particular marker will be clicked,\n    # it will display the sentiment value along with the corresponding place\n\n    for j in range(0, len(data)):\n        try:\n            if data.iloc[j]['sentiment'] > 0:\n                folium.Marker([data.iloc[j]['lat'], data.iloc[j]['lon']],\n                              popup=\"Sentiment :  \" + str(round(data.iloc[j]['sentiment'], 3)) + \" nLocation :\" + str\n                              (data.iloc[j]['name']),\n                              icon=folium.Icon(color='green')).add_to(m)\n            elif data.iloc[j]['sentiment'] &lt; 0:\n                folium.Marker([data.iloc[j]['lat'], data.iloc[j]['lon']],\n                              popup=\"Sentiment :  \" + str(round(data.iloc[j]['sentiment'], 3)) + \" nLocation: \" + str\n                              (data.iloc[j]['name']),\n                              icon=folium.Icon(color='red')).add_to(m)\n            else:\n                folium.Marker([data.iloc[j]['lat'], data.iloc[j]['lon']],\n                              popup=\"Sentiment :  \" + str(round(data.iloc[j]['sentiment'], 3)) + \" nLocation : \" + str\n                              (data.iloc[j]['name']),\n                              icon=folium.Icon(color='blue')).add_to(m)\n        except:\n            # print(\"error\"+str(j))\n            pass\n    m.save(list_sheetnames_geo[i] + \"_geo.html\")<\/code><\/pre>\n<\/div>\n<p>After running the above python folium script, the geographical maps are stored in html files. We have created the geographical visualization maps for each of the fashion brands.<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image8.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image8.png\" alt=\"\" width=\"2848\" height=\"1398\" class=\"aligncenter size-full wp-image-27611\" srcset=\"\/wp-content\/uploads\/2021\/06\/image8.png 2848w, \/wp-content\/uploads\/2021\/06\/image8-300x147.png 300w, \/wp-content\/uploads\/2021\/06\/image8-1024x503.png 1024w, \/wp-content\/uploads\/2021\/06\/image8-768x377.png 768w, \/wp-content\/uploads\/2021\/06\/image8-1536x754.png 1536w, \/wp-content\/uploads\/2021\/06\/image8-2048x1005.png 2048w, \/wp-content\/uploads\/2021\/06\/image8-600x295.png 600w\" sizes=\"(max-width: 2848px) 100vw, 2848px\" \/><\/a> The sentiment distribution looks like this across the globe for Rana Plaza incident response. As we can see the red marker depicts the negative sentiment whereas the green ones correspond to positive sentiment. We can zoom in to a particular area to find the detailed distributio of sentiment values. For example, the detailed sentiment distribution for the fashion brands in UK area looks like this.<\/p>\n<p><a href=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image9.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/griddb.net\/wp-content\/uploads\/2021\/06\/image9.png\" alt=\"\" width=\"2192\" height=\"1304\" class=\"aligncenter size-full wp-image-27612\" srcset=\"\/wp-content\/uploads\/2021\/06\/image9.png 2192w, \/wp-content\/uploads\/2021\/06\/image9-300x178.png 300w, \/wp-content\/uploads\/2021\/06\/image9-1024x609.png 1024w, \/wp-content\/uploads\/2021\/06\/image9-768x457.png 768w, \/wp-content\/uploads\/2021\/06\/image9-1536x914.png 1536w, \/wp-content\/uploads\/2021\/06\/image9-2048x1218.png 2048w, \/wp-content\/uploads\/2021\/06\/image9-600x357.png 600w\" sizes=\"(max-width: 2192px) 100vw, 2192px\" \/><\/a><\/p>\n<p>The geographical distribution helps fashion brands to focus on their weak areas where the customers are unhappy with their products and services.<\/p>\n<p><strong>Conclusion:<\/strong><\/p>\n<p>We performed sentiment analysis on the twitter dataset and visualized the sentiment using line chart, wordclouds, dendrograms and plotted on the geographical map. In the part -1 of the blog, we discussed how to fetch and retrieve the twitter data using GridDB. Hence, We can deploy cloud triggers to automate the sentiment analysis and export the sentiment insights to the various fashion brands for better marketing practices.<\/p>\n<p><strong>Source Code<\/strong> <a href=\"https:\/\/github.com\/07manisha\/TwitterSentimentAnalysis-2\">Github<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In the part-1 of the blog, we implemented GridDB python script to save and retrieve the Twitter data. In this blog, we will continue with the sentiment analysis and visualization of the sentiment data. We will calculate the sentiment values for each and every tweet, store the sentiment values, and visualize them to draw [&hellip;]<\/p>\n","protected":false},"author":41,"featured_media":26149,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[121],"tags":[],"class_list":["post-46653","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.1.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Twitter Sentiment Analysis with GridDB - Visualization of Sentiment Data (part-2) | GridDB: Open Source Time Series Database for IoT<\/title>\n<meta name=\"description\" content=\"Introduction In the part-1 of the blog, we implemented GridDB python script to save and retrieve the Twitter data. In this blog, we will continue with the\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Twitter Sentiment Analysis with GridDB - Visualization of Sentiment Data (part-2) | GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"og:description\" content=\"Introduction In the part-1 of the blog, we implemented GridDB python script to save and retrieve the Twitter data. In this blog, we will continue with the\" \/>\n<meta property=\"og:url\" content=\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/\" \/>\n<meta property=\"og:site_name\" content=\"GridDB: Open Source Time Series Database for IoT\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/griddbcommunity\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-07-01T07:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-11-13T20:55:26+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.griddb.net\/wp-content\/uploads\/2019\/08\/python-blog.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1160\" \/>\n\t<meta property=\"og:image:height\" content=\"653\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"griddb-admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:site\" content=\"@GridDBCommunity\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"griddb-admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/\"},\"author\":{\"name\":\"griddb-admin\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233\"},\"headline\":\"Twitter Sentiment Analysis with GridDB &#8211; Visualization of Sentiment Data (part-2)\",\"datePublished\":\"2021-07-01T07:00:00+00:00\",\"dateModified\":\"2025-11-13T20:55:26+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/\"},\"wordCount\":907,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/griddb.net\/en\/#organization\"},\"image\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2019\/08\/python-blog.png\",\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/\",\"url\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/\",\"name\":\"Twitter Sentiment Analysis with GridDB - Visualization of Sentiment Data (part-2) | GridDB: Open Source Time Series Database for IoT\",\"isPartOf\":{\"@id\":\"https:\/\/griddb.net\/en\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#primaryimage\"},\"thumbnailUrl\":\"\/wp-content\/uploads\/2019\/08\/python-blog.png\",\"datePublished\":\"2021-07-01T07:00:00+00:00\",\"dateModified\":\"2025-11-13T20:55:26+00:00\",\"description\":\"Introduction In the part-1 of the blog, we implemented GridDB python script to save and retrieve the Twitter data. In this blog, we will continue with the\",\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#primaryimage\",\"url\":\"\/wp-content\/uploads\/2019\/08\/python-blog.png\",\"contentUrl\":\"\/wp-content\/uploads\/2019\/08\/python-blog.png\",\"width\":1160,\"height\":653},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/griddb.net\/en\/#website\",\"url\":\"https:\/\/griddb.net\/en\/\",\"name\":\"GridDB: Open Source Time Series Database for IoT\",\"description\":\"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL\",\"publisher\":{\"@id\":\"https:\/\/griddb.net\/en\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/griddb.net\/en\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/griddb.net\/en\/#organization\",\"name\":\"Fixstars\",\"url\":\"https:\/\/griddb.net\/en\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"contentUrl\":\"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png\",\"width\":200,\"height\":83,\"caption\":\"Fixstars\"},\"image\":{\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/griddbcommunity\/\",\"https:\/\/x.com\/GridDBCommunity\",\"https:\/\/www.linkedin.com\/company\/griddb-by-toshiba\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233\",\"name\":\"griddb-admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/griddb.net\/en\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g\",\"caption\":\"griddb-admin\"},\"url\":\"https:\/\/www.griddb.net\/en\/author\/griddb-admin\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Twitter Sentiment Analysis with GridDB - Visualization of Sentiment Data (part-2) | GridDB: Open Source Time Series Database for IoT","description":"Introduction In the part-1 of the blog, we implemented GridDB python script to save and retrieve the Twitter data. In this blog, we will continue with the","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/","og_locale":"en_US","og_type":"article","og_title":"Twitter Sentiment Analysis with GridDB - Visualization of Sentiment Data (part-2) | GridDB: Open Source Time Series Database for IoT","og_description":"Introduction In the part-1 of the blog, we implemented GridDB python script to save and retrieve the Twitter data. In this blog, we will continue with the","og_url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/","og_site_name":"GridDB: Open Source Time Series Database for IoT","article_publisher":"https:\/\/www.facebook.com\/griddbcommunity\/","article_published_time":"2021-07-01T07:00:00+00:00","article_modified_time":"2025-11-13T20:55:26+00:00","og_image":[{"width":1160,"height":653,"url":"https:\/\/www.griddb.net\/wp-content\/uploads\/2019\/08\/python-blog.png","type":"image\/png"}],"author":"griddb-admin","twitter_card":"summary_large_image","twitter_creator":"@GridDBCommunity","twitter_site":"@GridDBCommunity","twitter_misc":{"Written by":"griddb-admin","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#article","isPartOf":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/"},"author":{"name":"griddb-admin","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233"},"headline":"Twitter Sentiment Analysis with GridDB &#8211; Visualization of Sentiment Data (part-2)","datePublished":"2021-07-01T07:00:00+00:00","dateModified":"2025-11-13T20:55:26+00:00","mainEntityOfPage":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/"},"wordCount":907,"commentCount":0,"publisher":{"@id":"https:\/\/griddb.net\/en\/#organization"},"image":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2019\/08\/python-blog.png","articleSection":["Blog"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/","url":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/","name":"Twitter Sentiment Analysis with GridDB - Visualization of Sentiment Data (part-2) | GridDB: Open Source Time Series Database for IoT","isPartOf":{"@id":"https:\/\/griddb.net\/en\/#website"},"primaryImageOfPage":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#primaryimage"},"image":{"@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#primaryimage"},"thumbnailUrl":"\/wp-content\/uploads\/2019\/08\/python-blog.png","datePublished":"2021-07-01T07:00:00+00:00","dateModified":"2025-11-13T20:55:26+00:00","description":"Introduction In the part-1 of the blog, we implemented GridDB python script to save and retrieve the Twitter data. In this blog, we will continue with the","inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb-linux-hte8hndjf8cka8ht.westus-01.azurewebsites.net\/en\/blog\/twitter-sentiment-analysis-with-griddb-visualization-of-sentiment-data-part-2\/#primaryimage","url":"\/wp-content\/uploads\/2019\/08\/python-blog.png","contentUrl":"\/wp-content\/uploads\/2019\/08\/python-blog.png","width":1160,"height":653},{"@type":"WebSite","@id":"https:\/\/griddb.net\/en\/#website","url":"https:\/\/griddb.net\/en\/","name":"GridDB: Open Source Time Series Database for IoT","description":"GridDB is an open source time-series database with the performance of NoSQL and convenience of SQL","publisher":{"@id":"https:\/\/griddb.net\/en\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/griddb.net\/en\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/griddb.net\/en\/#organization","name":"Fixstars","url":"https:\/\/griddb.net\/en\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/","url":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","contentUrl":"https:\/\/griddb.net\/wp-content\/uploads\/2019\/04\/fixstars_logo_web_tagline.png","width":200,"height":83,"caption":"Fixstars"},"image":{"@id":"https:\/\/griddb.net\/en\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/griddbcommunity\/","https:\/\/x.com\/GridDBCommunity","https:\/\/www.linkedin.com\/company\/griddb-by-toshiba"]},{"@type":"Person","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/4fe914ca9576878e82f5e8dd3ba52233","name":"griddb-admin","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/griddb.net\/en\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/5bceca1cafc06886a7ba873e2f0a28011a1176c4dea59709f735b63ae30d0342?s=96&d=mm&r=g","caption":"griddb-admin"},"url":"https:\/\/www.griddb.net\/en\/author\/griddb-admin\/"}]}},"_links":{"self":[{"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/posts\/46653","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/comments?post=46653"}],"version-history":[{"count":1,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/posts\/46653\/revisions"}],"predecessor-version":[{"id":51328,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/posts\/46653\/revisions\/51328"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/media\/26149"}],"wp:attachment":[{"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/media?parent=46653"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/categories?post=46653"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.griddb.net\/en\/wp-json\/wp\/v2\/tags?post=46653"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}