Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

normalize a group in countplot

import numpy as np
import pandas as pd
import seaborn as sns
sns.set(color_codes=True)

df = sns.load_dataset('titanic')
df.head()

x,y = 'class', 'survived'

(df
.groupby(x)[y]
.value_counts(normalize=True)
.mul(100)
.rename('percent')
.reset_index()
.pipe((sns.catplot,'data'), x=x,y='percent',hue=y,kind='bar'))


Comment

PREVIOUS NEXT
Code Example
Python :: production mode flask 
Python :: boto 3 list EMR 
Python :: how to form .cleaned data in class based views in django 
Python :: how to create a 2d array in python 
Python :: dictionary input from user in python3 
Python :: python numpy array subtract 
Python :: python check if string contains symbols 
Python :: import user model 
Python :: how to run python code in python 
Python :: recursion in python 
Python :: assignment operators in python 
Python :: get full path of document 
Python :: pca in python 
Python :: set default palette seaborn 
Python :: net way to print 2d array 
Python :: remove key from dictionary python 
Python :: matplotlib use marker along variable 
Python :: remove rows from dataframe 
Python :: df loc 
Python :: how to count all files on linux 
Python :: smtp python 
Python :: python get file ending 
Python :: how to loop through an array in python 
Python :: how to normalize scipy cross correlation 
Python :: refer dataframe with row number and column name 
Python :: show percentage in seaborn countplot site:stackoverflow.com 
Python :: python declare variable 
Python :: convert ipynb to py 
Python :: Program to Compute LCM Using GCD 
Python :: string representation of date time 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =