[PYTHON] Seaborn basics for beginners ① Aggregate graph of the number of data (Countplot)

What is seaborn

A library for drawing Python graphs. .. Positioned as a wrapper function (inclusive program) of matplotlib, the most famous libra. In addition to being able to easily draw beautiful-looking graphs, it also has a certain amount of functions such as batch processing. Matplotlib is for detailed specification and drawing, and seaborn is for easy and beautiful.

Preparation

First, install the seaborn library with pip. For pip ?, click here ('https://qiita.com/Yanagawa_Yoshihisa/items/35e6f70a8411277282ce').

Import the library. Name seaborn`` sns and ʻimport`.

python


import seaborn as sns

I will try the sample with Titanic data. If you don't know Titanic, please check "kaggle Titanic". Create a dataframe with pandas.

python


dataframe = pd.read_csv('train.csv')

Data count (Countplot)

This is the aggregate visualization of the number of the most basic data. Use Count plot for this. Basically, the Y axis is the number of cases, so specify only the X axis. As an example, draw the relationship between Pclass (room grade) and the number of cases. Specify P class for the X-axis x and data frame for the original data data.

python


sns.countplot(x="Pclass", data=dataframe)

image.png If you specify the Y axis, it will lie down.

python


sns.countplot(y="Pclass", data=dataframe)

image.png

If you want to add a series, add hue. (As an example, add Sex to hue.)

python


sns.countplot(y="Pclass", data=dataframe, hue='Sex')

image.png

You can also change the order and color of the axes, so if you are interested, please check it out. Also, changing the label can be done by modifying matplotlib, which is the original wrapper source, but it is complicated and will be omitted. With Count plot, the benefits may not be felt. I think that other distplot`` pairplot joint plot etc. will be more beneficial.

Finally

As a beginner can understand, we have summarized the necessary knowledge when implementing machine learning with Python as a simple article. The table of contents is here, so I hope you can refer to other articles as well.

Recommended Posts

Seaborn basics for beginners ① Aggregate graph of the number of data (Countplot)
Basics of pandas for beginners ② Understanding data overview
Seaborn basics for beginners ④ pairplot
Seaborn basics for beginners ② Histogram (distplot)
[Must-see for beginners] Basics of Linux
Learn the basics of Python ① Beginners
Align the number of samples between classes of data for machine learning with Python
[Translation] NumPy Official Tutorial "NumPy: the absolute basics for beginners"
python beginners tried to predict the number of criminals
I tried the MNIST tutorial for beginners of tensorflow.
[Linux] Basics of authority setting by chmod for beginners
[For beginners] Quantify the similarity of sentences with TF-IDF
Seaborn basics for beginners ③ Scatter plot (jointplot) * With histogram
[Introduction to logarithmic graph] Predict the end time of each country from the logarithmic graph of infection number data ♬
[For beginners] I want to explain the number of learning times in an easy-to-understand manner.
[For beginners] Basics of Python explained by Java Gold Part 2
Analyzing data on the number of corona patients in Japan
[Understand in the shortest time] Python basics for data analysis
[Homology] Count the number of holes in data with Python
Get the number of occurrences for each element in the list
Pandas basics for beginners ④ Handling of date and time items
[Python] The biggest weakness / disadvantage of Google Colaboratory [For beginners]
[Python] Introduction to graph creation using coronavirus data [For beginners]
What beginners learned from the basics of variables in python
[For beginners] Basics of Python explained by Java Gold Part 1
10. Counting the number of lines
Get the number of digits
Overview of Docker (for beginners)
Calculate the number of changes
Connected components of the graph
Aggregate the number of hits per second for one day from the web server log with Python
I checked the distribution of the number of video views of "Flag-chan!" [Python] [Graph]
Studying web scraping for the purpose of extracting data from Filmarks # 2
Pandas basics for beginners ① Reading & processing
Get the number of views of Qiita
Pandas basics for beginners ⑧ Digit processing
Shift the data for 3 months Shift the data for n months
Calculation of the number of Klamer correlations
Review of the basics of Python (FizzBuzz)
Get the number of Youtube subscribers
Pandas basics summary link for beginners
About the basics list of Python basics
[For beginners] Script within 10 lines (5. Resample of time series data using pandas)
Approach commentary for beginners to be in the top 1.5% (0.83732) of Kaggle Titanic_3
Graph of the history of the number of layers of deep learning and the change in accuracy
Graph the ratio of topcoder, Codeforces and TOEIC by rating (Pandas + seaborn)
[Example of Python improvement] What is the recommended learning site for Python beginners?
Graph the change in the number of keyword appearances per month using pandas
Approach commentary for beginners to be in the top 1.5% (0.83732) of Kaggle Titanic_1
[For beginners] Why are the "weights" and "bias" of neural networks necessary?
Get the key for the second layer migration of JSON data in python
Approach commentary for beginners to be in the top 1.5% (0.83732) of Kaggle Titanic_2
[Introduction to Data Scientists] Basics of scientific calculation, data processing, and how to use the graph drawing library ♬ Environment construction