I have two data frames as an example below:
df1 = pd.DataFrame({'URL': ['A','B','C'],
'X': [1,0,1],
'Y': [0,1,0],
'Z':[1,0,0]})
df2 = pd.DataFrame({'URL': ['D','E','F'],
'X': [0,1,0],
'Y': [1,0,0],
'Z':[1,0,0]})
I plotted a bar graph for the first data frame using the following code:
df1.melt("URL").\
groupby("variable").\
agg(Non_Tracking_websites=("value", lambda x: sum(x != 0))).\
plot(kind="bar")
And for the second data frame I used the same scenario and plotted the graph as below:
df2.melt("URL").\
groupby("variable").\
agg(Tracking_websites=("value", lambda x: sum(x != 0))).\
plot(kind="bar")
Now I want to merge the two bar graphs keeping the same scenarios as above. The final bar graph should look like this:
If anyone can help me, It would be great. Thank you