Have you ever feel a need to visualize the data in various form. Visualizing the data give us a better idea how our dataset is distributed.
So this is the recipe on how we use seaborn to visualise a Pandas dataframe.
import pandas as pd
import random
import matplotlib.pyplot as plt
import seaborn as sns
We have imported various modules like pandas, random, matplotlib and seaborn which will be need for the dataset.
We have created a empty dataset and then by using random function we have created set of random data and stored in X and Y. We have used print function to print the dataset.
df = pd.DataFrame()
df['x'] = random.sample(range(1, 50), 25)
df['y'] = random.sample(range(1, 100), 25)
print(); print(df.head())
print(); print(df.tail())
So we will be ploting different plots by using seaborn.
sns.lmplot('x', 'y', data=df, fit_reg=False)
sns.lmplot('x', 'y', data=df, fit_reg=True)
sns.kdeplot(df.y); plt.show()
sns.kdeplot(df.y, df.x); plt.show()
sns.distplot(df.x); plt.show()
plt.hist(df.x, alpha=.3)
sns.rugplot(df.x)
plt.show()
sns.boxplot([df.y, df.x])
plt.show()
sns.violinplot([df.y, df.x])
plt.show()
sns.heatmap([df.y, df.x], annot=False, fmt="d")
plt.show()
sns.clustermap(df)
plt.show()
x y 0 15 22 1 36 61 2 39 71 3 3 46 4 38 85 x y 20 6 49 21 19 20 22 9 73 23 33 79 24 40 59