gpt4 book ai didi

bokeh - 如何将 GroupBy Count 显示为分类数据的 Bokeh vbar

转载 作者:行者123 更新时间:2023-12-01 04:37:26 32 4
gpt4 key购买 nike

我在创建 Bokeh 时遇到了一个小问题 vbar 在 0.13.0
来自数据帧 groupby count手术。回复 here是一个多层次的团体,而我的却不是。

发布后的更新

  • 根据提供的答案添加了示例数据和代码,以查看问题是我的代码还是其他问题

  • 大纲

    pandas 数据框包含调查回复
  • 优秀
  • 可怜
  • 满意
  • 很好

  • 栏目下 ('ResponseID','RateGeneral','RateAccomodation','RateClean','RateServices')并且 dtype 被设置为类别。我想通过使用显示响应计数组的 Bokeh vbar
    DemoDFCount = DemoDF.groupby('RateGeneral').count()

    我的 Bokeh 代码看起来像这样
    pTest= figure(title='Rating in General',plot_height=350)
    pTest.vbar(width=0.9,source=DemoDFCount, x='RateGeneral',top='ResponseID')
    show(pTest))

    但不产生任何图表只有标题和工具栏
    Bokeh

    如果我使用 Pandas DemoDFCount.plot.bar(legend=False)我可以绘制一些东西,但如何在 Bokeh 中创建此图表?
    dataframe bar plot

    示例数据作为 json 导出

    来自 DemoDF.to_json() 的 50 行样本数据
    '{"ResponseID":{"0":1,"1":2,"2":3,"3":4,"4":5,"5":6,"6":7,"7":8,"8":9,"9":10,"10":11,"11":12,"12":13,"13":14,"14":15,"15":16,"16":17,"17":18,"18":19,"19":20,"20":21,"21":22,"22":23,"23":24,"24":25,"25":26,"26":27,"27":28,"28":29,"29":30,"30":31,"31":32,"32":33,"33":34,"34":35,"35":36,"36":37,"37":38,"38":39,"39":40,"40":41,"41":42,"42":43,"43":44,"44":45,"45":46,"46":47,"47":48,"48":49,"49":50},"RateGeneral":{"0":"Good","1":"Satisfactory","2":"Good","3":"Poor","4":"Good","5":"Satisfactory","6":"Excellent","7":"Good","8":"Good","9":"Satisfactory","10":"Satisfactory","11":"Excellent","12":"Satisfactory","13":"Excellent","14":"Satisfactory","15":"Very Good","16":"Satisfactory","17":"Excellent","18":"Very Good","19":"Excellent","20":"Satisfactory","21":"Good","22":"Satisfactory","23":"Excellent","24":"Satisfactory","25":"Good","26":"Excellent","27":"Very Good","28":"Good","29":"Very Good","30":"Good","31":"Satisfactory","32":"Very Good","33":"Very Good","34":"Very Good","35":"Good","36":"Excellent","37":"Satisfactory","38":"Excellent","39":"Good","40":"Good","41":"Satisfactory","42":"Very Good","43":"Very Good","44":"Poor","45":"Excellent","46":"Good","47":"Excellent","48":"Satisfactory","49":"Good"},"RateAccomodation":{"0":"Very Good","1":"Excellent","2":"Satisfactory","3":"Satisfactory","4":"Good","5":"Good","6":"Very Good","7":"Very Good","8":"Good","9":"Satisfactory","10":"Satisfactory","11":"Excellent","12":"Satisfactory","13":"Excellent","14":"Good","15":"Very Good","16":"Good","17":"Excellent","18":"Excellent","19":"Very Good","20":"Good","21":"Satisfactory","22":"Good","23":"Excellent","24":"Satisfactory","25":"Very Good","26":"Excellent","27":"Excellent","28":"Good","29":"Very Good","30":"Very Good","31":"Very Good","32":"Excellent","33":"Very Good","34":"Very Good","35":"Very Good","36":"Excellent","37":"Satisfactory","38":"Excellent","39":"Good","40":"Excellent","41":"Poor","42":"Very Good","43":"Very Good","44":"Poor","45":"Excellent","46":"Satisfactory","47":"Excellent","48":"Good","49":"Good"},"RateClean":{"0":"Excellent","1":"Excellent","2":"Satisfactory","3":"Good","4":"Excellent","5":"Very Good","6":"Very Good","7":"Excellent","8":"Excellent","9":"Satisfactory","10":"Satisfactory","11":"Excellent","12":"Good","13":"Good","14":"Excellent","15":"Excellent","16":"Good","17":"Excellent","18":"Excellent","19":"Excellent","20":"Good","21":"Very Good","22":"Poor","23":"Very Good","24":"Satisfactory","25":"Very Good","26":"Excellent","27":"Good","28":"Poor","29":"Good","30":"Excellent","31":"Good","32":"Good","33":"Very Good","34":"Satisfactory","35":"Good","36":"Excellent","37":"Satisfactory","38":"Excellent","39":"Good","40":"Very Good","41":"Satisfactory","42":"Excellent","43":"Excellent","44":"Very Good","45":"Excellent","46":"Good","47":"Excellent","48":"Good","49":"Excellent"},"RateServices":{"0":"Very Good","1":"Excellent","2":"Good","3":"Good","4":"Excellent","5":"Good","6":"Good","7":"Very Good","8":"Good","9":"Satisfactory","10":"Satisfactory","11":"Excellent","12":"Good","13":"Very Good","14":"Good","15":"Excellent","16":"Poor","17":"Excellent","18":"Excellent","19":"Excellent","20":"Good","21":"Good","22":"Very Good","23":"Excellent","24":"Satisfactory","25":"Very Good","26":"Excellent","27":"Very Good","28":"Good","29":"Excellent","30":"Very Good","31":"Excellent","32":"Good","33":"Excellent","34":"Very Good","35":"Very Good","36":"Excellent","37":"Satisfactory","38":"Excellent","39":"Good","40":"Very Good","41":"Satisfactory","42":"Excellent","43":"Excellent","44":"Good","45":"Excellent","46":"Very Good","47":"Excellent","48":"Good","49":"Very Good"}}'

    最佳答案

    在另一个问题中它是多层次的这一事实并不真正相关。当您使用 Pandas 时 GroupBy作为 Bokeh 的数据源,Bokeh 使用 group.describe 的结果(包括每组每列的计数)作为数据源的内容。这是一个完整的示例,显示了来自“汽车”数据集的 Counts-per-Origin:

    from bokeh.io import show, output_file
    from bokeh.plotting import figure
    from bokeh.sampledata.autompg import autompg as df

    output_file("groupby.html")

    df.origin = df.origin.astype(str)
    group = df.groupby('origin')

    p = figure(plot_height=350, x_range=group, title="Count by Origin",
    toolbar_location=None, tools="")

    # using yr_count, but count for any column would work
    p.vbar(x='origin', top='yr_count', width=0.8, source=group)

    p.y_range.start = 0
    p.xgrid.grid_line_color = None

    show(p)

    enter image description here

    关于bokeh - 如何将 GroupBy Count 显示为分类数据的 Bokeh vbar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51499376/

    32 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com