Simple Plot Graph with Python: capital letters matters

Today we will see how to create simple plot graphs in Python using Seaborn. I have found in a Data Science book (by Sinan Ozdemir) a simple graph where we can plot sales and expenditure in advertising for different media like TV, Radio, Newspaper.

Let’see how it works. Where is better to put the money? First of all import pandas and seaborn  packages and dataset

import pandas as pd
import seaborn as sns
data = pd.read_csv('http://www-bcf.usc.edu/~gareth/ISL/Advertising.csv', index_col=0) #import data in CSV format using Pandas
data.head() # let'see how data are structured

TV radio newspaper sales
1 230.1 37.8 69.2 22.1
2 44.5 39.3 45.1 10.4
3 17.2 45.9 69.3 9.3
4 151.5 41.3 58.5 18.5
5 180.8 10.8 58.4 12.9

Let’s plot the data using some magic… and using seaborne package we can say to Python, to plot data having 3 x_vars, based on our 3 first column of our database, and on y_vars sales. Let’s see the result

%matplotlib inline
sns.pairplot(data, x_vars=['TV','radio','newspaper'], y_vars=['sales'], size=4.5, aspect=0.7)
Plot graph of sales for different media

But image to write the same commands now with Radio & Newspaper with capital letter. Python is very sensitive (or at least Anaconda version that I’m using), so take care of using correct name of variable.

matplotlib inline
sns.pairplot(data, x_vars=['TV','Radio','Newspaper'], y_vars=['sales'], size=4.5, aspect=0.7)

Where to find correct Variable name? You can see it from:

  • the head of your table
  • In Anaconda, on the Variable explorer in column Value

If you need further info on magic function, %matplotlib inline, you can have a look to this post on Stackoverflow

Did you like this post on a simple plot graph.  Share it to friends, colleagues or martians using below buttons and do not forget to subscribe to our fun newsletter.

How to impress your boss: Infographics, dashboard, visualization tools

An image worth more than thousand of data, sorry words. Yes, sometimes you have a lot of data to present in a very small period of data. What is better than a good dashboard where to see in a glance your KPI’s or a nice infographics to show tons of info in few seconds?

People don’t have time, so having all in one page is very useful to present but also to make a good storytelling to help your audience to digest complex info and memorize important messages.

63% of your audience could remember stories, but only 5% could remember a single statistic (Source: Stanford professor Chip Heath)

Create an infographics

You can simply create an infographics with Picktochart

Infographics Photo by rawpixel on Unsplash
Infographics Photo by rawpixel on Unsplash

Here how it works:

  • Sign in to piktochart
  • Define a template 
  • Select from the left menu with icon, graphics that you want to change or adjust (graphics, background, text, color, tools) 
  • On the top side you can save, share or download

Below you can find some examples 

A simple but powerful infographics could be found here:

How quitting smoking affect your body

Infographics on Pinterest

What now you have to do is just think about which are the data that you would like to present and how to create a good storytelling that your audience will remind.

If you need to analyze quickly your data, consider to read: How to analyze your data in 5 minutes with Panda.

Build your dashboard in 5 minutes

Dashboard helps you to understand immediately what is going well (maybe showing green numbers, up arrows) and where to investigate more maybe with other self-service reports.  

An example of interactive dashboard
An example of interactive dashboard -Photo by rawpixel on Unsplash

To create powerful visualization you need to fulfill the following requirements:

What I want to explain with this dashboard? Maybe I want to show if we have reach our sales target, or which are the most contributors for growth or products that are in delay

Test how simple and easy to read is your dashboard: go to one of your colleague with less familiarity with technology and ask to explain the content of our report. If he/she report the right message you have created a good one. Otherwise interview other people on what is difficult to read or unclear and simplify.

Create your dashboard: you have several tools to create it:

  • Excel: Best info At Chandoo.org where you will discover how to create and manage your dashboard.
  • Python: More complicated but you can define every aspect of your dashboard. 
    • Plotly and Bokeh are the modules that you can use to excel on this topic. 
    • An interesting example is this Bokeh dashboard or Kickstarter project by category and status (successfull, cancelled…) including also name of the project if you pass through 

An example of kickstarter dashboard done in Bokeh
An example of kickstarter dashboard done in Bokeh

  • R: Best choice: Here you can customize everything, using Shiny and Rmarkdown using less code than Python. 
    • An interesting example is R Cran download monitor, where in one page you can see evolution of package download, name 

CRAN download - R dashboard example
CRAN download – R dashboard example

 

 

 

 

 

 

 

 

If you want more please consider in subscribing to our fun newsletter and our recent posts