0

I have dataframe like this

df = pd.DataFrame({'_3321131460': ['col1', 'col1', 'col2'], '_3952604542': ['col1', 'col2', 'col2']})
df

So want to create graph like this enter image description here

one graph but x are two columns and legent have two columns data

And y is count But know how to do that

So one columns histogram, another columns histogram in one graph

But have same legend

1 Answer 1

2

You can transform your df with melt in order to have the column names in their own column:

import pandas as pd
import plotly.express as px 

df = pd.DataFrame({'_3321131460': ['col1', 'col1', 'col2'], '_3952604542': ['col1', 'col2', 'col2']})
df_t = df.melt()

This will have the following form (feel free to rename the columns to get fitting labels on your final plot):

      variable value
0  _3321131460  col1
1  _3321131460  col1
2  _3321131460  col2
3  _3952604542  col1
4  _3952604542  col2
5  _3952604542  col2

Then use px.bar:

fig = px.bar(df_t, x='variable', color='value', barmode="group")
fig.show()

Output: enter image description here

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so muchhhhhh!! i dont think solution melt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.