Skip to content Skip to sidebar Skip to footer

How To Make A Grouped Bar Chart

I have this dataframe and want to plot it as a grouped bar chart. I checked this question (Grouped Bar graph Pandas), It has a group with its value, not columns. How can I have a g

Solution 1:

I think you need reshape by set_index with unstack first:

df1 = df.set_index(['category', 'num_thread', 'num_iter'])['time'].unstack()
#python 3.6+
df1.index = [f'{i}{j}' for i, j in df1.index]
#python under 3.6
#df1.index = ['{}{}'.format(i, j) for i, j in df1.index]
print (df1)
num_iter   100000000  200000000  400000000
OMP2        692.5336  1398.5305  2765.7757
OMP4        362.1932   724.6331  1447.0628
OMP8        193.0222   382.7540   759.3889
OMP16       102.5276   214.6385   450.7183
ORIGINAL1  1360.0577  2731.8207  5440.8003
PTHREAD2    697.3113  1388.6210  2779.8507
PTHREAD4    363.9816   721.6508  1432.9843
PTHREAD8    189.8591   379.8860   764.2684
PTHREAD16   124.2015   238.9460   478.0660

df1.plot.bar()

Post a Comment for "How To Make A Grouped Bar Chart"