How to Level Up as a Data Scientist using Seaborn
By: Florian Geiser
Tags: Machine Learning, Education, Data Science, Work, Programming

How to Level Up as a Data Scientist using Seaborn

Stand out between competitors and impress customers

Seaborn’s example gallery part 1

Different job announcements require different skill sets. As a data scientist, you probably read a lot about Numpy, Matplotlib, Pandas, Tensorflow, and so on. Without deep knowledge in these Python libraries you probably have a hard time on job interviews for data scientists. This is not a secret and most applicants know they should be capable to handle them. So, how to stand out between competitors, present your outcome in a beautiful manner, and excite your customers? Use seaborn!

What is Seaborn?

The process of collecting data and managing it is already annoying enough. Working on that data takes time and effort. So why compromising on presenting the outcome of something you really worked hard on?

Hold on! There is an easy way to impress your audience: seaborn!

Seaborn is a visualization library for Python to not only create beautiful plots but also make your life easier. It can be seen as an extension of the matplotlib library and works perfectly fine with pandas data structures. For probably every data set you have, you can find the right graphs and plots. Furthermore, the outcome looks way more attractive than other plots.

What makes Seaborn so Awesome?

1. Pandas Integration

Since you are a smart data scientist, you are already using the pandas data frame. So, import the necessary libraries including seaborn and pandas:

import pandas as pd

import seaborn as sns

Find the table of your choice, import it, and you can already show the table’s head:

tips = pd.read_csv(‘tips.csv’)

tips.head()

Image taken by the author.

Now we are ready to create a stunning plot with a simple one-liner:

sns.distplot(tips[‘total_bill’])

Image taken by the author.

2. Simplicity

There is no easier way to present your data in an attractive way than using seaborn. Once your data is imported and ready, you can change and manipulate plots in a single line of code!

sns.swarmplot(x="day", y="total_bill", data=tips)

Image taken by the author.

3. Advanced plots

Most other standard libraries can create a simple and boring histogram too. But how about a plot, which makes other data scientists almost envy? Use:

sns.jointplot(x=’total_bill’, y=’tip’, data=tips, kind=’scatter’)

to not only get a histogram including a kernel density estimation on each axis but also a two-dimensional scatter plot, together with a regression trajectory.

Image taken by the author.

Still not the plot you are looking for? No problem, how about a boxplot:

sns.boxplot(x=”day”, y=”total_bill”, hue=”smoker”, data=tips)

Image taken by the author.

And even a grid of different plots is no big deal at all. Import the table of your choice:

iris = pd.read_csv('iris.csv')

Create a grid with:

g = sns.PairGrid(iris)

And finally, fill the grid with data:

g.map_diag(plt.hist)

g.map_upper(plt.scatter)

g.map_lower(sns.kdeplot)

Image taken by the author.

4. Appearance

Bored about finding matching colors for your graphs? With the palette argument, you can modify the whole appearance without taking care of matching colors. They simply do!

sns.pairplot(tips,hue=’sex’, palette=’coolwarm’)

Image taken by author.

What are you waiting for?

As you can see, seaborn enables plenty of new opportunities in plotting your data. The library includes graphs you probably didn’t know, they even exist. Find more excellent plots in the example gallery and choose the one-liner of code you need to modify.