0

everyone!

I don't have the dataset with me so I'll make a mock code to simulate what I'm trying to do. Here's the code:

import pandas as pd
import seaborn as sns
  
# intialise data of lists.
data = {'Name':['Tom', 'Nick', 'Kevin', 'Jack'],
        'Sales Q1':[2024, 2421, 2219, 2018],
        'Sales Q2':[2822, 2144, 1992, 2558]}
  
# Create DataFrame
df = pd.DataFrame(data)
  
# Print the output.
df

I haven't really been able to search good ways to solve this but I'm trying to have it so the results look like...

enter image description here

I could create bar charts through SNS but it ultimately can't hue between the Name bracket. Any suggestions? Thanks!

Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
ESarousi
  • 47
  • 7

1 Answers1

0

IIUC, you can try:

import matplotlib.pyplot as plt
import seaborn as sns

df1 = df.melt(id_vars='Name')
sns.barplot(x='Name', y='value', hue='variable', data=df1)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)

enter image description hereOUTPUT

Nk03
  • 14,699
  • 2
  • 8
  • 22
  • So that looks great but the thing is that your answer has value in your df as all in one column. I have two columns with values and I want those to be next to each other. – ESarousi Jun 18 '21 at 18:14
  • @ESarousi Here `Q1/Q2` values are separate `Q1` is in blue while `Q2` is in orange and they're next to each other. Can you try the solution once? Not getting what i missed. – Nk03 Jun 18 '21 at 19:32
  • What I'm trying to say is that it certainly appears from what I see that both values are within a single column "variable". In my example, I don't know which column would be the hue and which would be the y. – ESarousi Jun 18 '21 at 21:32