Last month I shared some of the things I had learned while playing around with the Google Trends Python library, PyTrends.
While collecting the data using this method is super fun and efficient, it's only really the start of what you can do with Python. Once we have the data saved in a Pandas DataFrame, our next step is to visualise the data.
In order to do this I wanted to share three different fun and fairly simple ways to visualise the data we have stored from Google Trends.
Let's start with Matplotlib
What is Matplotlib?
Matplotlib is a Python library for creating plotting visualisations. There are lots of different things you can create with Matplotlib, such as bar charts, line graphs, histograms and even heatmaps.
Bar Charts with Matplotlib
In order to try out Matplotlib with the Google Trends data, I took the rising related queries that I collected for the term BTS, and created two different bar charts.
The first bar chart is a typical chart, with the queries along the x-axis and the values on the y-axis.
In order to do this I used the rcParams in order to update the size and styling of the plot, as well as the font colour and size.
I used a similar command in order to create a horizontal bar chart, which features the query along the y-axis and the value along the x. In this example, the top rising keyword is at the bottom of the graph.
Next up is Seaborn
What is Seaborn?
What is Seaborn?
Seaborn is another data visualisation library used in Python, and is actually based on Matplotlib.
Seaborn provides different visualisation patterns such as scatterplots, boxplots and violinplots, as well as line and bar graphs. It differs slightly from Matplotlib as it uses fewer syntax and has built in default themes.
For the Seaborn example, I took the interest over time data for the 5 dog breeds, and plotted a really simple line graph to show the spikes and dips in interest over time.
I also played around with some of the styling options available in order to change the overall size of the chart using
figsize, as well as the font size. In addition, I used the style and palette functions in order to change the background grid to dark and the lines on the graph to be bright. This helped it to become slightly more visually appealing and easier to understand.
Google Sheets and Google DataStudio
And we can't forget the crown jewels of SEO data visualisation, Google Data Studio. We can use the Google Sheets integration to create dashboards for the data we have collected from Google Trends.
For this example, we are going to take the data from our trending DataFrame in order to create a simple table in GDS.
To begin with, we need to connect Google Colab to Google Sheets and create an empty spreadsheet to push our data to.
We then need to take a custom formula, which is written by Daniel Cook.
Then we can use the pandas_to_sheets command to send the data from our already created DataFrame to our newly created spreadsheet.
When we have our data safely in the Google Sheets spreadsheet, we then need to create a new data connector for Google Data Studio, using the Google Sheets integration and select the relevant spreadsheet.
Once we have this connector set up, we can then create a Data Studio report, using our Google Sheets data source, and choose the chart which best fits what we want to visualise. For our trending data, I have created a really simple table to display the trending search terms.
Another visualisation we can create is using the related topics rising keywords and creating a horizontal bar chart to display the most popular keywords first. In order to create this we just need to follow the same steps as above, and change the chart type.