SNIPPET
3 Upvotes

Discrete Variable Combinations

Python
Visualisation & EDA

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)
	plt.figure(figsize=(10,6))
	sns.heatmap(pivot,cmap='Reds')
	plt.show()

feature_interactions(data,'room_type','neighbourhood_group','price')
{{ snippet.title}

By analyseup - Last Updated Sept. 16, 2021, 3:46 p.m.

COMMENTS
RELATED SNIPPETS
2
Search Snippets by Tag: