简体   繁体   English

按两个标准分组的直方图 [python]

[英]Histograms grouping by two criteria [python]

I have a dataset like this:我有一个这样的数据集: 在此处输入图片说明

I need to plot this dataset based on two criteria: Churn and Cust_Value.我需要根据两个标准绘制此数据集:Churn 和 Cust_Value。

I can do it using seaborn:我可以使用 seaborn 做到这一点:

sns.barplot(x="Cust_Value", y="value", hue="Churn", data=merged)
plt.show()

The result gives me:结果给了我: 在此处输入图片说明

How can I add all variables (value, age, reloads, calls, duration, sms, gprs, inactive) to the same graph as groups of bars?如何将所有变量(值、年龄、重新加载、调用、持续时间、短信、gprs、非活动)添加到与条形组相同的图表中?

for that kind of output i would recommend using plotly,对于那种输出,我建议使用 plotly,

import plotly.plotly as py
import plotly.graph_objs as go

trace1 = go.Bar(
    x=DF['Cust_Value'],
    y=DF['value'],
    name='value'
)
trace2 = go.Bar(
    x=DF['Cust_Value'],
    y=DF['age'],
    name='age'
)
trace3 = go.Bar(
    x=DF['Cust_Value'],
    y=DF['calls'],
    name='calls'
)

data = [trace1, trace2, trace3]
layout = go.Layout(
    barmode='group'
)

fig = go.Figure(data=data, layout=layout)
py.iplot(fig, filename='grouped-bar')

sample output:示例输出:

在此处输入图片说明

reference: https://plot.ly/python/bar-charts/参考: https : //plot.ly/python/bar-charts/

hope it helps!希望能帮助到你!

if it does upvote :)如果它确实赞成:)

peace和平

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM