Python Seaborn - 3 |BAR PLOTS in Python Using Seaborn Library with MEAN, MEDIAN, SUM, COUNT agg

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in the previous video we learned what is count plot and how to draw that here we are going to learn about power plot bar plot is very identical to the count plot but the only restriction is in count plot we can only figure out the counts of categorical variables but here we can get different statistical aggregation like mean media etc so if you can look at these pictures this look very much similar to the count plot but here we have these error bars as well so you can have columnar a bar plot horizontal bar plots you can have same colored bar plots and many more you can do with the bar plots help hello everyone welcome to the channel learn area and to understand the concept very clearly please watch the video till the end once you are done with watching the video please do not forget to like comment subscribe and hit the bell icon if you visit to its official website it shows you this definition and this is the complete syntax for bar plot which i am not going to explain all because these are most likely not used always if you are interested in understanding each of these parameters i will be providing the link of its ops official website in the description section do not hesitate to visit that and learn that it's gonna be useful for you now here we are in the jupiter notebook and we will cover each of these things there are 13 items which we will cover don't get scared of this list because it's going to be very simple and very friendly in learning so i will be covering each of these very quickly in this video stay with me now here the first thing is to import all the required libraries which is going to be import pandas as pd then numpy then matplotlib dot pi plot as plt and then the library which we are learning which is c bond as sns now all that i need to do is just hit control enter this this all these libraries are imported now here i would just show you a demo how can you import the data sets provided with c bond library and that can be used in your exercise but here i would be just showing you for how to import them but i won't be using them in the exercise because we are referring to the sales smart data and that will be continued right so here let me show you how to get the name of all the data sets provided with c1 sns dot you can simply say get and hit tab from your keyboard and then parenthesis operator and hit control plus enter so these are all the list of these are the these are the items data sets available under c bond library right so whatever data sets if you want to import you can just select that from here and how can you load that so for that you're gonna say sns dot okay let me create a data from frame and then sns dot load data set and in the bracket you can just provide the data set name which you want to import that has been imported how you can see that for that you can just say head so this is how you can import the data frame from c1 library itself but here in our case we are referring to super market data sales so that i will be importing using pd dot grid excel and the location here i already have used that so i will copy it from here itself just to save the time this is my location from where i will be importing this data and here i will just show you the top and rows for from this data set top five rows from this data set so if you see these all are the variables and in our analysis we will be using three variable one is product line the other one is total and then the zender right so in product line it shows what are the product categories what are the total amount this product has been sold for and which category of customer has done this much of purchases so these three variables we will be using in this tutorial to create the bar plots and its variations so let's start with creating a basic bar plot how can we do that for that sns bar plot and in that you need to provide the value for x-axis on x-axis i want to plot product line because for for each of the product line i want to see the average sales right and on y-axis i would put total that is the total amount of sell for each of the product and i will be taking the average of that so and then it comes what is the data that i want to use so mod data i want to use over here now here our plot has been created so if you see the only problem which i see over here is product line name is not very clear so to fix that we can use the figure method from matplotlib for that i gonna say pld if you remember plt is the abbreviation for matplotlib pipeline if you see over here so this from same module i will be using figure plt dot figure and in that i would use fixed size and i will define a figure size first this is the width of figure and then this is the height of figure all right now we have the product lines written very clearly so if you see this it says fashion accessories average sales of fashion accessories are somewhere 300. this is the error bar this is called the error bar which generally shows you the variation of data anyway the definition of error bar is not in the scope of this video which we will be covering in our statistical tutorials for now if you are interested you can just google it and you can understand its definition next thing we which we gonna do is i'll just copy this just to save the time and next thing which we will be doing is adding the u to our bar graph what is hue q is nothing just the third dimension to our graph if you see this is just two dimensional right and we will be creating a third dimension which will be categorical again right and that will show us let's say we want to see for example here we can see fashion accessories have been sold on an average for 300 right then we want to distribute it in on the basis of gender how how much it has been sold to male and how much it has been sold to female so for that we can just use we can just use hue parameter so for you in that we will say gender and just comma and run this now you can see for fashion accessories the total was 300 and the distribution is like this for uh sorry average for fashion accessories was 300 now a fashion accessories average for female is more than 300 which is somewhere 3.25 uh 325 and for male it is exactly 300 somewhere right so this is how you can use the u parameter in your bargain now it says make the bar plot horizontal as of now you just saw we whatever we created those those all were vertical means columnar now we want to make it a horizontal form how can we do that nothing much needs to be done is you just need to switch the value for x-axis and y-axis previously we had categorical variable on x-axis now we're going to put that on y-axis and on x-axis we are going to put the numeric variable which is total and this will change the columnar bar into the horizontal bar horizontal bar right so if you want you can add all those features which we just experienced on columnar bar over here as well so this is how you can create the you can just change the orientation of your bar graph moving forward here it says plot the bars in a given order right the problem statement over here says plot the bars in a given order for example if you see it over here this is not alphabetically arranged but for some reason if you want to have this arranged alphabetically for example over here as well or maybe in any order whatever order you want that you can also do for example let's first draw this bar graph and then we will try to arrange this if you want you can keep you as well right so let's see this so here we have all the parts created over here now but these are not alphabetically arranged so we will arrange them alphabetically if you see over here all the product lines i have just sorted in alphabetic order and then i have i'll just take a list from here which are sorted you can also do those sorting and everything is going to be the same here i just need to say order and in order i will just put that list over here but the one thing which we we need to do over here is just remove all these stuffs and here i need to close this okay and this that's it let's run this now if you see that has been alphabetically arranged if you want you can change the this order as well you order as well right so in here it is first showing female and then showing male if you want you can first show male and then female as well you order and in that you can say male and then female let's run this see if it works wow it just worked now it's doing first male then female so this is how you can use the order parameter in bar graph next it says add cap on the error bar so the error bar which you just see over here these are just line if you want to add caps on that that you can also do let me just show you that quickly how can you do that i will for the sake of saving the time what i'll do i'll just copy this syntax from here and i'll just put it here and then i'll add the another parameter which is called cap size and in cap size i would say 0.2 let's run this now you can see on the error bar this cap has been created so this is how you can create the cap size as well now it says remove the error bar we we want to create a bar chart but we don't want to have this default error bar in that scenario what you can do is just say sky c i this is called the class interval and in that we just need to say none and this will remove this error bar now you can see error bar has been removed next thing comes changing the color these are in different colors let's say if you want to change its color to a different form right let's say i want to keep it in one color so for that you can say let's say black so everything will be black because we have a hue also so that's why it is showing in black and white if you remove this hue from here and then run this everything is going to be black now if you want to change this to red that you can also do it is change to red so this is how you can play with color selection as well next it comes changing the palette so let's see this how can we do that let me just put it over here and for now what i'll do is let me just remove hue so that it will show you it will create a pattern of colors nothing much just it will give you a pattern of color palette and you don't know what are the palettes which can be accepted over here so you can just do this and you can hit enter in the error it will show you the accepted values so these all are the accepted value for palette you can choose any one of them and you can just put it over here and then run this now if you see this is showing you a pattern of colors this is just not uniform color it is giving you a pattern of color but here when you use color parameter it was just giving you one color so this is how you can play around it and you can use different palettes right and you can make it different if you want to use you that you can also do now you equals to gender let me run this now you have this kind of cue now let's change try to change the saturation of this color right so these are uh in saturation we will be just changing the measurement of color combinations right so let me just put it over here i'll use this i'll just copy this syntax and i will put it over here and over here i'm just going to say saturations and in saturation let's put the saturation 0.5 and let's see how it changes the color so if you see the difference this one is lighter than this one if you want you can make it five this will be more darker than that than the above one so similarly you can play around saturation as well right if you want you can just make it 0.1 so you see the differences so this is how we can change the saturation of the color now the most important part which is the default aggregation function the default aggregation function is mean so if you create a bar graph and you don't provide a specific function by default it gives you the mean but if you want you can change change that as well how can you change that simply you need to say estimator you need to choose estimator and in that let's say i want to see the sum so you can do that you can just type some and you can see the sum of them now if you see the value have been changed over here previously it the maximum value was 400 and now this is 40 000 certainly this is sum if you want you can change this to median as well if you want to see the median of each of this product line by gender that you can also do for that you can just say np dot media but here if you see num by library will be important so well this is how you can use the bar bar plot which comes under c bond and you can draw your bar graph on your data and you can change the attributes of it to make it look more attractive or in the way whatever you thank you very much for watching the video i just hope that i was able to clarify the doubts on bar plots just in case if you get some more doubt do not hesitate to put that into the comment section and we will definitely try to resolve that and get back to you thank you very much for watching the video wish you very good luck
Info
Channel: Learnerea
Views: 6,698
Rating: undefined out of 5
Keywords: bar plot, seaborn bar plot, bar plot with mean median count sum
Id: NzHaePgIToo
Channel Id: undefined
Length: 17min 23sec (1043 seconds)
Published: Wed Oct 20 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.