Answer by BhishanPoudel for Pandas groupby two columns and plot
Various Methods of Groupby PlotsDataimport numpy as npimport pandas as pddf = pd.DataFrame({'category': list('XYZXY'),'sex': list('mfmff'),'ThisColumnIsNotUsed': range(5,10)})dfcategory sex...
View ArticleAnswer by plasmon360 for Pandas groupby two columns and plot
You can also use thispd.pivot_table(df, values = 'B', index = 'category', columns = 'sex', aggfunc = lambda x: len(x)).plot.bar()which results in exactly the same plot.
View ArticleAnswer by Vaishali for Pandas groupby two columns and plot
IIUC,df.groupby(['category','sex']).B.count().unstack().reset_index()\.plot.bar(x = 'category', y = ['f', 'm'])Edit: If you have multiple columns, you can use groupby, count and droplevel.new_df =...
View ArticlePandas groupby two columns and plot
I have a dataframe like this:import numpy as npimport pandas as pdimport matplotlib.pyplot as plt%matplotlib inlinedf = pd.DataFrame({'category': list('XYZXY'), 'B': range(5,10),'sex': list('mfmff')})I...
View Article