0

I currently have an existing dataframe with country, mode of arrival and arrival count. I am hoping to create a grouped bar chart but I only know how to create regular bar charts.

This is the formula I am using for now

trace3 = go.Bar(x=df5['cor'],y=df5['arv_count'], name = 'Total arrival count by country in 2013')
iplot([trace3])

This is how the graph looks like:

enter image description here

2
  • can you please the groups of your dataframe Commented Jul 17, 2019 at 5:22
  • I want to group it by mode of arrival. By air, land,sea. @AnkushRasgon Commented Jul 17, 2019 at 9:19

1 Answer 1

2

I hope this answers your question.Pandas will show grouped bars by columns. Entries in each row but different columns will constitute a group in the resulting plot. Therefore, you need to do something like,

df5.pivot("cor", "arrival", "arv_count").plot(kind='bar')
plt.show()
Sign up to request clarification or add additional context in comments.

2 Comments

An error message of "Index contains duplicate entries, cannot reshape" shows up @Shafiqa Iqbal
You must have index with multiple duplicate values. try this df5.reset_index().pivot("cor", "arrival", "arv_count").plot(kind='bar')

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.