Data Wrangling
Importing Data Select, Drop & Rename Filter, Sort & Sample Add Columns Cleaning Data Dates & Time Join Data Aggregate & Transform
Data Analysis
Exploring Data Plotting Continuous Variables Plotting Discrete Variables
Machine Learning
Data Preparation Linear Models
Other Tutorials & Content
Learn Python for Data Science Learn Alteryx Blog

Discrete Variable Plots with Seaborn & Matplotlib

Single Variable Count Plot

Create a count plot showing the frequency of the different levels of the room_type column in the data DataFrame using Seaborn Countplot:

sns.countplot(x='room_type', data=data)

Two Variable Count Plot

Create a count plot showing the frequency of the different levels of the room_type and neighbourhood_group columns in the data DataFrame:

sns.countplot(x='room_type', hue='neighbourhood_group', data=data)
View Our Profile on to See Our Data Science Code Snippets

Box Plot

Create a box plot showing the price ranges for different levels in the neighbourhood_group column of the data DataFrame using Seaborn Boxplot. The range of the y axis has been set to 0 - 600 to improve the readability of the chart.

sns.boxplot(x='neighbourhood_group', y='price's,data=data)

Comparing Means

Compare the mean price for each level in the neighbourhood_group column using a Pandas GroupBy and Seaborn barplot:

def compare_means(df,discrete_col,continuous_col):
group = df.groupby([discrete_col],as_index=False)[continuous_col].mean().reset_index(drop=True)
plt.ylabel('mean ' + continuous_col)


Discrete Variable Combinations

Compare the mean price for the combinations of levels in the neighbourhood_group and room_type columns using Pandas Pivot and Seaborn Heatmap:

def feature_interactions(df,feature1, feature2,continuous_col):
group = df.groupby([feature1,feature2],as_index=False)[continuous_col].mean().reset_index(drop=True)
pivot = group.pivot(index=feature1, columns=feature2, values=continuous_col)
pivot.fillna(0, inplace=True)