Recipe: How to use seaborn to visualise a Pandas dataframe?
DATA VISUALIZATION PANDAS CHEATSHEET

How to use seaborn to visualise a Pandas dataframe?

This recipe helps you use seaborn to visualise a Pandas dataframe
In [2]:
## How to use seaborn to visualise a Pandas dataframe
def Snippet_111():
    print()
    print(format('How to use seaborn to visualise a Pandas dataframe','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    import pandas as pd
    import random
    import matplotlib.pyplot as plt
    import seaborn as sns

    df = pd.DataFrame()
    df['x'] = random.sample(range(1, 50), 27)
    df['y'] = random.sample(range(1, 100), 27)
    print(); print(df.head())
    print(); print(df.tail())

    # Scatterplot
    sns.lmplot('x', 'y', data=df, fit_reg=False)

    # Scatterplot with regression line
    sns.lmplot('x', 'y', data=df, fit_reg=True)

    # Density Plot
    sns.kdeplot(df.y); plt.show()
    sns.kdeplot(df.y, df.x); plt.show()
    sns.distplot(df.x); plt.show()

    # Histogram
    plt.hist(df.x, alpha=.3)
    sns.rugplot(df.x)
    plt.show()

    # Boxplot
    sns.boxplot([df.y, df.x]); plt.show()

    # Violin Plot
    sns.violinplot([df.y, df.x]); plt.show()

    # Heatmap
    sns.heatmap([df.y, df.x], annot=False, fmt="d"); plt.show()

    # Clustermap
    sns.clustermap(df); plt.show()

Snippet_111()
****************How to use seaborn to visualise a Pandas dataframe****************

    x   y
0  32  72
1  27  58
2  42   7
3   5  55
4  45  68

     x   y
22   9  94
23  20  16
24  13  62
25  22  78
26  44  15


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
1 developer from Vodafone
1 developer from ANAC
1 developer from Wipro
1 developer from HvH
1 developer from Tata Consultancy Services