1

I have the following Dataframe: Dataframe

I want to plot it into a bar chart. With 3 bars, 1 for Positive, 1 for Neutral and 1 for Negative. Im trying this:

fig = px.bar(senti_df, x=senti_df.index, y=['Positive', 'Neutral', 'Negative'])
fig.show()

But all I get as a result is this: Output

How can I plot them side by side? And is there a possibility to plot it into a pie chart? Thank you so much for your help, I'm a beginner :(

2 Answers 2

1

I'd like to use raw-like data, therefore, we have some transformation via melt()

df = pd.DataFrame({'Positive':[17], 'Neutral':[26], 'Negative':[7], 'Währung':['Bitcoin(BTC)']})
df2 = df.melt(value_vars=['Positive','Neutral','Negative'], id_vars=['Währung'], var_name='connotation')

print(df2)
        Währung connotation  value
0  Bitcoin(BTC)    Positive     17
1  Bitcoin(BTC)     Neutral     26
2  Bitcoin(BTC)    Negative      7



Plot bar chart

fig_bar = px.bar(df2, x='Währung', y='value', color='connotation', barmode='group')
fig_bar.show()

enter image description here




Plot pie chart

fig_pie = px.pie(df2, values='value', names='connotation')
fig_pie.show()

enter image description here

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

1 Comment

Thank you so much! Exactly what I was looking for. I'll upvote as soon as I have enough reputation.
0

You can do this by adding the parameter barmode='group':

fig = px.bar(senti_df, x='Währung', y=['Positive', 'Neutral', 'Negative'],  barmode='group')

Output:

enter image description here

Documentation

barmode (str (default 'relative')) – One of 'group', 'overlay' or 'relative' In 'relative' mode, bars are stacked above zero for positive values and below zero for negative values. In 'overlay' mode, bars are drawn on top of one another. In 'group' mode, bars are placed beside each other.

Comments

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.