Quantcast
Channel: Pandas groupby two columns and plot - Stack Overflow
Browsing latest articles
Browse All 4 View Live

Image may be NSFW.
Clik here to view.

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 Article



Image may be NSFW.
Clik here to view.

Answer 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 Article

Image may be NSFW.
Clik here to view.

Answer 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 Article

Image may be NSFW.
Clik here to view.

Pandas 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
Browsing latest articles
Browse All 4 View Live




Latest Images