How to build two DataFrames on the same chart for comparison

I have two DataFrames (trail1 and trail2) with the following columns: Genre, City and Number Sold. Now I want to create a histogram of both datasets for matching in size Genre and Total Number Sold. For each genre, I want two bars: one representing track 1, and the other representing track 2.

How can I achieve this using Pandas?

I tried the following approach, which did NOT work.

gf1 = df1.groupby(['Genre'])
gf2 = df2.groupby(['Genre']) 
gf1Plot = gf1.sum().unstack().plot(kind='bar, stacked=False)
gf2Plot = gf2.sum().unstack().plot(kind='bar, ax=gf1Plot, stacked=False)

I want to see how the trail1 dataset is compared with the trial2 data for each of the genres (for example: spicy, sweet, sour, etc.)

I also tried using concat, but I can't figure out how to graphically concatenate a DataFrame on the same graph in order to compare two keys.

DF = pd.concat([df1,df2],keys=['trail1','trail2'])
+4
2

. , .

:

df1 = pd.DataFrame(myData1, columns=['Genre', 'City', 'Sold'])
df2 = pd.DataFrame(myData2, columns=['Genre', 'City', 'Sold'])

df1['Key'] = 'trail1'
df2['Key'] = 'trail2'

DF = pd.concat([df1,df2],keys=['trail1','trail2'])

DFGroup = DF.groupby(['Genre','Key'])

DFGPlot = DFGroup.sum().unstack('Key').plot(kind='bar')

: enter image description here

+10

, merge, concat. :

DF = pd.merge(df1,df2,on=['Genre','City'])
DF.Groupby([['Genre','City']]).sum().unstack().plot(kind = 'bar')
0

All Articles