Using Seaborn To Visualize A Pandas Dataframe

Want to learn more? I recommend these Python books: Python for Data Analysis, Python Data Science Handbook, and Introduction to Machine Learning with Python.

Preliminaries

import pandas as pd
%matplotlib inline
import random
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame()

df['x'] = random.sample(range(1, 100), 25)
df['y'] = random.sample(range(1, 100), 25)
df.head()
x y
0 14 52
1 88 92
2 39 69
3 19 98
4 60 76

Scatterplot

sns.lmplot('x', 'y', data=df, fit_reg=False)
<seaborn.axisgrid.FacetGrid at 0x10dc2b1d0>

png

Density Plot

sns.kdeplot(df.y)
<matplotlib.axes._subplots.AxesSubplot at 0x10c30e050>

png

sns.kdeplot(df.y, df.x)
<matplotlib.axes._subplots.AxesSubplot at 0x10c5536d0>

png

sns.distplot(df.x)
<matplotlib.axes._subplots.AxesSubplot at 0x10b669550>

png

Histogram

plt.hist(df.x, alpha=.3)
sns.rugplot(df.x);

png

Boxplot

sns.boxplot([df.y, df.x])
<matplotlib.axes._subplots.AxesSubplot at 0x10a5c9b50>

png

Violin Plot

sns.violinplot([df.y, df.x])
<matplotlib.axes._subplots.AxesSubplot at 0x10dca4b50>

png

Heatmap

sns.heatmap([df.y, df.x], annot=True, fmt="d")
<matplotlib.axes._subplots.AxesSubplot at 0x10dab5110>

png

Clustermap

sns.clustermap(df)
<seaborn.matrix.ClusterGrid at 0x10de304d0>

png