Tutorial to write SQL queries using Python and visualizing the results in Tableau - Part 4

Tutorial to write SQL queries using Python and visualizing the results in Tableau - Part 4
Photo by Alex Suprun / Unsplash

It is a very interesting fact that the colour white has the highest resale value, ever wondered why?

It is all the game of demand and supplies, the people generally tend to buy a white used car than a green, grey, or custom one.

Similarly, we have been drawing inferences about which colour vehicle is sold at the highest price. Colour is not the only thing that is the deciding factor for a car buyer but it is one of the important ones!

So, let's learn how to analyze and visualize the same using Python and Tableau respectively.

Dataset: Vehicles.csv

SQL Query in Python

!pip install pandasql
import pandas as pd
pd.set_option('display.max_rows', 100)
pd.options.display.float_format = '{:.5f}'.format
import pandasql as ps
from IPython.display import HTML
sql_query = """SELECT Avg(price)AS average_price,
       paint_color
FROM   vehicles
WHERE  price BETWEEN 1 AND 655000
GROUP  BY paint_color
ORDER  BY average_price DESC; """

res_df = ps.sqldf(sql_query, locals())
HTML(res_df.to_html(escape=False))

Visualizing the result in Tableau

Start by dragging paint colour in columns and Avg(price) in rows.

Now, automatically a Bar graph would appear to depict the data.

We can see that among all the bars 'Silver' has the highest average price, which means that silver is the highest selling used car colour.

Now, we can change the visualization using the 'Show me' button on the top right corner which has all the other feasible options that can be chosen to show the visualization.

On selecting the packed bubbles visualization we can see that the visualization comes with the bubble graph which plots the data in a way that the largest bubble denotes the highest average price of the colour and vice versa.

Thus from the above visualization, we can see that silver has the highest average price among other paint colours used on cars.

Thus, this way we can show the particular SQL query in Tableau.

Conclusion

The tableau can do a lot of work for you if you know how to use it right. The best way to make someone understand interpretations is by visualizing them and doing so with your SQL queries using Tableau can teach you the right way to do so.

In this series, we have tried to teach something new in every blog, if you've reached this far you have made some progress in your Tableau journey.

Keep practising!

It was all, until next time!