0

I have a dataframe that look like the following

               TrgID           SenName  SignalToNoise    date
0  20201001000732016                a      1.645613  2020-10-01
1  20201001000732016                b      2.601088  2020-10-01
2  20201001000732016                c      1.253404  2020-10-01
3  20201001000732017                a      6.062578  2020-10-01
4  20201001000732017                b      2.753620  2020-10-01
5  20201001000732017                c      3.671336  2020-10-01
6  20201001000732018                a      1.466516  2020-10-01
7  20201001000732018                b      1.232844  2020-10-01
8  20201001000732018                c      2.028571  2020-10-01
9  20210331234440962                a     11.182038  2020-10-02
10 20210331234440962                b     11.413975  2020-10-02
11 20210331234440962                c     14.690728  2020-10-02
12 20210331234440963                a      1.228948  2020-10-02
13 20210331234440963                b      1.105445  2020-10-02
14 20210331234440963                c      2.035442  2020-10-02
15 20210331234440964                a      2.453167  2020-10-02
16 20210331234440964                b      2.075166  2020-10-02
17 20210331234440964                c      1.140017  2020-10-02

I would like to create a stacked bar chart where x axis is date and the y-axis is stacked with the Signal to "SignalToNoise" value stacking the "SenName"

what I have so far is:

ax = df.plot.bar(x = 'date', y = 'SignalToNoise')

However, I just get a separate bar for each entry in my df. Most of the examples demonstrating values from different columns. Any help greatly appreciated.

How can

Spooked
  • 586
  • 1
  • 4
  • 16
  • 3
    Do you want: `df.pivot_table(index='date', columns='SenName', values='SignalToNoise', aggfunc='sum').plot.bar(stacked=True)`? – mozway Mar 27 '23 at 13:19
  • 1
    @mozway yes that is what I am chasing! – Spooked Mar 27 '23 at 13:25
  • @mozway as a follow up question how would I move the legend? my full data set has a lot more values for SenName and ends up overlapping the chart itself? – Spooked Mar 27 '23 at 13:39
  • Don't forget to search, those questions [already have answers](https://stackoverflow.com/questions/23556153/how-to-put-legend-outside-the-plot-with-pandas) ;) – mozway Mar 27 '23 at 13:44

0 Answers0