0

I am going to kick myself when I get the answer, but I am specifically stuck on how to shape my dataframe so that I can use the grouped bar graph feature with seaborn. Specifically, I would like all columns except labels to become features on the x-axis and the label column to be used to identify groupings within each feature. Setting hue="Label" only allows me to select one column for analysis. I have also tried setting the Label column as the index, but still stuck on how to plot all the columns on the same graph.

import pandas as pd
x={'COL1A1': {0: 0.2833579201349264, 1: 0.2322427823226963, 2: 0.2234481446366325, 3: 0.1713271996532782, 4: 0.1706736234267313, 5: 0.2168315586062242, 6: 0.386938532513836, 7: 0.167685047602447, 8: 0.1977671674206828}, 'COL1A2': {0: 0.222790260323129, 1: 0.1166248272594191, 2: 0.1213743347438685, 3: 0.07539620593306488, 4: 0.08646408377942773, 5: 0.108099072823806, 6: 0.2253577413174345, 7: 0.07159756158725838, 8: 0.1270212586927018}, 'COL2A1': {0: 0.1177084047971632, 1: 0.03015204272416201, 2: 0.004641911872949625, 3: 0.01252004151673348, 4: 0.004759507378467226, 5: 0.003771667678394546, 6: 0.002448538354908414, 7: 0.001632213095114248, 8: 0.002689169456628402}, 'COL3A1': {0: 0.07704183889927835, 1: 0.05669627792749389, 2: 0.06795005563919726, 3: 0.06820333109906228, 4: 0.06203084779960908, 5: 0.07143978702722126, 6: 0.1075883977017228, 7: 0.02325396568594267, 8: 0.04019275033210956}, 'COL4A1': {0: 0.0006352541367984844, 1: 0.0003530402330976581, 2: 0.0002599951224169368, 3: 0.001068552848567594, 4: 0.0004283762535061793, 5: 0.0001828315856020066, 6: 0.0007922674417145188, 7: 0.00121122295479909, 8: 0.001242371369354}, 'ELN': {0: 0.009590516917155572, 1: 0.01128331824126868, 2: 0.001767761425242979, 3: 0.001335871032556882, 4: 0.0006832478350178915, 5: 6.156058814047895e-05, 6: 4.641718558203665e-05, 7: 0.0007894520340958474, 8: 0.0}, 'FN1': {0: 0.2916957262974497, 1: 0.2991922242655564, 2: 0.2604020611939179, 3: 0.3750793271445748, 4: 0.3947768543681868, 5: 0.3544762810478779, 6: 0.2691587576010813, 7: 0.1879022759492052, 8: 0.2388673352144315}, 'Label': {0: 'DAT', 1: 'DAT', 2: 'DAT', 3: 'DCT', 4: 'DCT', 5: 'DCT', 6: 'TCP', 7: 'TCP', 8: 'TCP'}}    
df=pd.DataFrame(x)

Any help would be appreciated.

Image of Data:

Actual Dataframe

Mr. T
  • 11,141
  • 9
  • 27
  • 51
thejahcoop
  • 128
  • 10
  • 1
    Hello again. Please don't post data/code/error messages as images. Post the text directly here on SO. See also: https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – Mr. T Feb 24 '21 at 20:59
  • my bad, changing it now. I forgot – thejahcoop Feb 24 '21 at 21:02
  • 1
    [You mean like this?](https://stackoverflow.com/a/49505519/8881141) I suggest reading also this about [long vs wide format](https://seaborn.pydata.org/tutorial/data_structure.html) plots in seaborn. – Mr. T Feb 24 '21 at 21:13
  • Yes, it could just be the end of the day, but I can't wrap my head around using melt for the solution. I'll take a closer look at it and thank you for the second. – thejahcoop Feb 24 '21 at 21:20
  • Yep, I'm just overworked and exhausted. I figured it out.....i think. I will post my code as an answer when I work it out. Thanks again! – thejahcoop Feb 24 '21 at 21:25

1 Answers1

2
ECMxx=pd.read_excel('ECMx.xlsx', sheet_name='Sheet2')
data = ECMxx.melt('Label', var_name='ECM', value_name='Intensity/Total Intensity')
fig = plt.figure(figsize=(10,10))
sns.set(font_scale = 1.2)
sns.set_style("white")
ax=sns.barplot(y='ECM', x='Intensity/Total Intensity', hue='Label', data=data)

Product

thejahcoop
  • 128
  • 10