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

  • @anirudhvenkataramanan4321
    @anirudhvenkataramanan43212 жыл бұрын

    Thank you Jonathan! The explanation was very clear. Hope your channel goes a long way :)

  • @k_abhishek2056
    @k_abhishek20562 жыл бұрын

    Thank you Jonathan .Your explanation was really good . Please upload more videos of pandas.❤🥳👍

  • @mayamathew4669
    @mayamathew4669 Жыл бұрын

    Thank you. Very informative video.

  • @sinuhkl
    @sinuhkl2 жыл бұрын

    Hi, how can you add labels to the crosstab bar chart?

  • @noorool10
    @noorool102 жыл бұрын

    Hello. Is there any way to adjust the size of the bars?

  • @ahmedyacinebouchouareb911
    @ahmedyacinebouchouareb911 Жыл бұрын

    jonathan the saviour

  • @briansmith3905
    @briansmith39052 жыл бұрын

    7:30 ...Is that a car revving in the background? I kept looking out my front window.

  • @ruchinashakya1171
    @ruchinashakya1171 Жыл бұрын

    Can we use the crosstab data to plot the percent stacked bar chart when we have an entry value 0.

  • @jsoma

    @jsoma

    Жыл бұрын

    To have crosstab calcluate the percentage for you, add normalize='index', normalize='columns', or normalize=True. Hope that helps!

  • @xpathservice2179
    @xpathservice21793 жыл бұрын

    what is the name the bird making that noise?

  • @jsoma

    @jsoma

    3 жыл бұрын

    No idea, I just hope he doesn't file a copyright claim

  • @BlueSkyGoldSun
    @BlueSkyGoldSun2 жыл бұрын

    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!!

Келесі