Pandas stacked bar chart

前端 未结 2 1365
日久生厌
日久生厌 2021-01-16 06:33

I have the following dataset:

SessionId    Query
   1           a   
   1           b
   2           a
   3           b
   3           b
   3           c
            


        
2条回答
  •  醉梦人生
    2021-01-16 06:49

    Pandas stacked bar chart relies on plotting different columns, so you'd need to pivot your data table to get the queries as columns holding the number of queries in rows.

    Try this:

    df = pd.DataFrame({"session":[1,1,2,2,3,3],
                  "query":list("ababab"), "count":[5,7,32,5,8,1]})
    df.pivot("session","query").plot(kind="bar", stacked=True)
    

    Output:

提交回复
热议问题