Python Seaborn - 2 | Creating a COUNT PLOT or FREQUENCY PLOT to See the Frequency Distribution

Поділитися
Вставка
  • Опубліковано 21 лип 2024
  • Python Seaborn - 1 | Creating a COUNT PLOT or FREQUENCY PLOT or COLUMNER PLOT or BAR PLOT to See the Frequency Distribution of a Categorical Variable
    This video covers:
    00:00 - Introduction
    01:00 - Importing Seaborn and other required libraries
    01:43 - Importing excel data file
    02:45 - Creating a basic COUNTPLOT to show the frequency/count of values in a given categorical variable
    04:11 - Changing/Adjusting the figure size of a plot figure
    05:53 - Horizontal count plot | Bar plot to show the count | Convert the count plot to horizontal bars
    06:46 - Creating a count plot for two categorical variables | Adding hue to the count plot
    08:26 - Changing the color of columns in count plot using color palette
    09:49 - Changing the style of count plot i.e. changing face color, line width, edge color or line color
    You can download the excel files used in this video using:
    File Name : supermarket_sales.xlsx
    URL : github.com/LEARNEREA/Python/t...
    You can download the script created in this video using:
    File Name : 2.Seaborn_CountPlot.py
    URL : github.com/LEARNEREA/Python/t...
    Seaborn Official website for count plot:
    seaborn.pydata.org/generated/...
    #python #pythonforbeginners #VisualizationInPython #seaborn #visualizationUsingSeaborn #CountPlotUsingSeaborn
  • Наука та технологія

КОМЕНТАРІ • 28

  • @learnerea
    @learnerea  Рік тому

    To have numbers at bars/columns -
    import seaborn as sns
    import matplotlib.pyplot as plt
    # load the iris dataset
    iris = sns.load_dataset('iris')
    # create a count plot of the species column
    ax = sns.countplot(x='species', data=iris)
    # add count values to the bars
    for p in ax.patches:
    ax.annotate(format(p.get_height(), '.0f'), (p.get_x() + p.get_width() / 2., p.get_height()),
    ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
    plt.show()

  • @greycatturtle
    @greycatturtle Рік тому +2

    Wow, this is exactly what I needed thank you for explaining it so well!

  • @chandrakantasahoo1736
    @chandrakantasahoo1736 Рік тому +1

    very nicely explained all , thanks

    • @learnerea
      @learnerea  Рік тому

      Hope that helped. Keep watching

  • @saswatachatterjee4213
    @saswatachatterjee4213 8 місяців тому +1

    Thanks sir for this beautiful session...

  • @enricoroselino7557
    @enricoroselino7557 2 роки тому +1

    spot on tutorial thank u

  • @bensalahali30
    @bensalahali30 2 роки тому +2

    Thank you.

  • @zeynabazimi7442
    @zeynabazimi7442 10 місяців тому

    Hello. Thank you for all the useful videos. On 2:05, when you want to read the excel file, you have this drop down menu of functions. Could you let me know how you added it to jupyter notebook? Thanks.

    • @learnerea
      @learnerea  10 місяців тому +1

      when you write "pd." just prcess Tab key from your keyboard and you will get that dropdown. Enjoy:)

  • @KeerthivasanSundararaman
    @KeerthivasanSundararaman Рік тому +1

    hey thanks for the video.. if i want the actual number in each of the bars how do it get it

    • @learnerea
      @learnerea  Рік тому

      will make a video on this soon, in the meantime, you can use this for reference -
      www.geeksforgeeks.org/how-to-show-values-on-seaborn-barplot/

  • @sukhmanisahaji9827
    @sukhmanisahaji9827 Рік тому

    Hey this tutorial is great, but I'm getting numbers on the labels for x-axis instead of column names on it. How do I fix this?

    • @learnerea
      @learnerea  Рік тому

      try below -
      You may find it little lengthier, try the below -
      import seaborn as sns
      import matplotlib.pyplot as plt
      # load the iris dataset
      iris = sns.load_dataset('iris')
      # create a count plot of the species column
      ax = sns.countplot(x='species', data=iris)
      # add count values to the bars
      for p in ax.patches:
      ax.annotate(format(p.get_height(), '.0f'), (p.get_x() + p.get_width() / 2., p.get_height()),
      ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
      plt.show()

  • @umamaheswararaom7909
    @umamaheswararaom7909 2 роки тому

    If there is number on x-axis and count on y axis , how to give range for x axis, how to change range on y axis like (5,10, 15)

    • @learnerea
      @learnerea  2 роки тому

      Hi Uma,
      try below -
      sns.countplot(data=your_df,x="your_x_label_column")
      plt.ylim(min_number_you_want_to_start_from,max_number_you_want_to_start_from)
      for example, I have this data -
      data = {"Gender":[1,3,2,3,1,2,3,2,1,3,1],
      "Income":[80,34,40,45,50,90,70,60,45,40,85]}
      and I want to ploat "Gender" on x axis and want see the count in range between 3 to 12 then this is waht I'll do
      sns.countplot(data=df,x="Gender")
      plt.ylim(3,12)
      DO NOT FORGET TO IMPORT - import matplotlib.pyplot as plt
      let me know if this helps or not

  • @johnedwards7024
    @johnedwards7024 Рік тому

    How would you add labels to the plot to indicate the actual number?

    • @learnerea
      @learnerea  Рік тому

      You may find it little lengthier, try the below -
      import seaborn as sns
      import matplotlib.pyplot as plt
      # load the iris dataset
      iris = sns.load_dataset('iris')
      # create a count plot of the species column
      ax = sns.countplot(x='species', data=iris)
      # add count values to the bars
      for p in ax.patches:
      ax.annotate(format(p.get_height(), '.0f'), (p.get_x() + p.get_width() / 2., p.get_height()),
      ha = 'center', va = 'center', xytext = (0, 10), textcoords = 'offset points')
      plt.show()

  • @sadikaljarif9635
    @sadikaljarif9635 2 роки тому +1

    where is frequency distribution???countplot and fdist both are different right?

    • @learnerea
      @learnerea  2 роки тому

      What sort of frequency you actually want see, if you can give an example, possibly I'll be able to suggest you a better solution

  • @programmingholic
    @programmingholic Рік тому

    bro not getting suggestion on palette, producing error

    • @learnerea
      @learnerea  Рік тому

      Suggseted in the comment on barplot.. alternatively you can also use -
      sns.color_palette
      to get the list

    • @uchindamiphiri1381
      @uchindamiphiri1381 Рік тому

      me too now lol