How to make grouped bar charts in pandas/Python with crosstab and pivot tables and more
Ғылым және технология
Building grouped bar charts in pandas can be a pain, since you need to understand how .plot() and matplotlib work AND get your data formatted correctly first. This video explains how .plot() works, what columns/rows do when plotting, and how to reshape or reorganize your data into a grouped-bar-chart-friendly format - we look at pivot_table, groupby + value_counts + reset_index or unstack, and crosstab. Not in-depth, but probably enough to tackle what you're trying to do!
Completed code: gist.github.com/jsoma/4654e70...
Other recommended graphing libraries:
Altair: altair-viz.github.io/
Seaborn: seaborn.pydata.org/index.html
If you're asking yourself "why are there so many bold words for index names or columns??" or "why did he have to do y='count' in that one spot???" I recommended giving a read about MultiIndexes: pandas.pydata.org/pandas-docs...
Пікірлер: 12
Thank you Jonathan! The explanation was very clear. Hope your channel goes a long way :)
Thank you Jonathan .Your explanation was really good . Please upload more videos of pandas.❤🥳👍
Thank you. Very informative video.
Hi, how can you add labels to the crosstab bar chart?
Hello. Is there any way to adjust the size of the bars?
jonathan the saviour
7:30 ...Is that a car revving in the background? I kept looking out my front window.
Can we use the crosstab data to plot the percent stacked bar chart when we have an entry value 0.
@jsoma
Жыл бұрын
To have crosstab calcluate the percentage for you, add normalize='index', normalize='columns', or normalize=True. Hope that helps!
what is the name the bird making that noise?
@jsoma
3 жыл бұрын
No idea, I just hope he doesn't file a copyright claim
Try using plotly for the grouped data, you are going suffer more. I feel sometimes pandas and plotly has no logic, you keep trying until it works by luck!!