简体   繁体   中英

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.

I can do it using 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?

for that kind of output i would recommend using 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/

hope it helps!

if it does upvote :)

peace

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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