{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Introduction to Seaborn\n", "> What is Seaborn, and when should you use it? In this chapter, you will find out! Plus, you will learn how to create scatter plots and count plots with both lists of data and pandas DataFrames. You will also be introduced to one of the big advantages of using Seaborn - the ability to easily add a third variable to your plots by using color to represent different subgroups. This is the Summary of lecture \"Introduction to Data Visualization with Seaborn\", via datacamp.\n", "\n", "- toc: true \n", "- badges: true\n", "- comments: true\n", "- author: Chanseok Kang\n", "- categories: [Python, Datacamp, Visualization]\n", "- image: " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import seaborn as sns\n", "\n", "plt.rcParams['figure.figsize'] = (10, 5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Introduction to Seaborn\n", "- What is seaborn\n", " - Python data visualization library\n", " - Easily create the most common types of plots\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Making a scatter plot with lists\n", "In this exercise, we'll use a dataset that contains information about 227 countries. This dataset has lots of interesting information on each country, such as the country's birth rates, death rates, and its gross domestic product (GDP). GDP is the value of all the goods and services produced in a year, expressed as dollars per person.\n", "\n", "We've created three lists of data from this dataset to get you started. `gdp` is a list that contains the value of GDP per country, expressed as dollars per person. `phones` is a list of the number of mobile phones per 1,000 people in that country. Finally, `percent_literate` is a list that contains the percent of each country's population that can read and write." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Country | \n", "Region | \n", "Population | \n", "Area (sq. mi.) | \n", "Pop. Density (per sq. mi.) | \n", "Coastline (coast/area ratio) | \n", "Net migration | \n", "Infant mortality (per 1000 births) | \n", "GDP ($ per capita) | \n", "Literacy (%) | \n", "Phones (per 1000) | \n", "Arable (%) | \n", "Crops (%) | \n", "Other (%) | \n", "Climate | \n", "Birthrate | \n", "Deathrate | \n", "Agriculture | \n", "Industry | \n", "Service | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "Afghanistan | \n", "ASIA (EX. NEAR EAST) | \n", "31056997 | \n", "647500 | \n", "48,0 | \n", "0,00 | \n", "23,06 | \n", "163,07 | \n", "700.0 | \n", "36,0 | \n", "3,2 | \n", "12,13 | \n", "0,22 | \n", "87,65 | \n", "1 | \n", "46,6 | \n", "20,34 | \n", "0,38 | \n", "0,24 | \n", "0,38 | \n", "
1 | \n", "Albania | \n", "EASTERN EUROPE | \n", "3581655 | \n", "28748 | \n", "124,6 | \n", "1,26 | \n", "-4,93 | \n", "21,52 | \n", "4500.0 | \n", "86,5 | \n", "71,2 | \n", "21,09 | \n", "4,42 | \n", "74,49 | \n", "3 | \n", "15,11 | \n", "5,22 | \n", "0,232 | \n", "0,188 | \n", "0,579 | \n", "
2 | \n", "Algeria | \n", "NORTHERN AFRICA | \n", "32930091 | \n", "2381740 | \n", "13,8 | \n", "0,04 | \n", "-0,39 | \n", "31 | \n", "6000.0 | \n", "70,0 | \n", "78,1 | \n", "3,22 | \n", "0,25 | \n", "96,53 | \n", "1 | \n", "17,14 | \n", "4,61 | \n", "0,101 | \n", "0,6 | \n", "0,298 | \n", "
3 | \n", "American Samoa | \n", "OCEANIA | \n", "57794 | \n", "199 | \n", "290,4 | \n", "58,29 | \n", "-20,71 | \n", "9,27 | \n", "8000.0 | \n", "97,0 | \n", "259,5 | \n", "10 | \n", "15 | \n", "75 | \n", "2 | \n", "22,46 | \n", "3,27 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
4 | \n", "Andorra | \n", "WESTERN EUROPE | \n", "71201 | \n", "468 | \n", "152,1 | \n", "0,00 | \n", "6,6 | \n", "4,05 | \n", "19000.0 | \n", "100,0 | \n", "497,2 | \n", "2,22 | \n", "0 | \n", "97,78 | \n", "3 | \n", "8,71 | \n", "6,25 | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
\n", " | school | \n", "sex | \n", "age | \n", "famsize | \n", "Pstatus | \n", "Medu | \n", "Fedu | \n", "traveltime | \n", "failures | \n", "schoolsup | \n", "... | \n", "goout | \n", "Dalc | \n", "Walc | \n", "health | \n", "absences | \n", "G1 | \n", "G2 | \n", "G3 | \n", "location | \n", "study_time | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "GP | \n", "F | \n", "18 | \n", "GT3 | \n", "A | \n", "4 | \n", "4 | \n", "2 | \n", "0 | \n", "yes | \n", "... | \n", "4 | \n", "1 | \n", "1 | \n", "3 | \n", "6 | \n", "5 | \n", "6 | \n", "6 | \n", "Urban | \n", "2 to 5 hours | \n", "
1 | \n", "GP | \n", "F | \n", "17 | \n", "GT3 | \n", "T | \n", "1 | \n", "1 | \n", "1 | \n", "0 | \n", "no | \n", "... | \n", "3 | \n", "1 | \n", "1 | \n", "3 | \n", "4 | \n", "5 | \n", "5 | \n", "6 | \n", "Urban | \n", "2 to 5 hours | \n", "
2 | \n", "GP | \n", "F | \n", "15 | \n", "LE3 | \n", "T | \n", "1 | \n", "1 | \n", "1 | \n", "3 | \n", "yes | \n", "... | \n", "2 | \n", "2 | \n", "3 | \n", "3 | \n", "10 | \n", "7 | \n", "8 | \n", "10 | \n", "Urban | \n", "2 to 5 hours | \n", "
3 | \n", "GP | \n", "F | \n", "15 | \n", "GT3 | \n", "T | \n", "4 | \n", "2 | \n", "1 | \n", "0 | \n", "no | \n", "... | \n", "2 | \n", "1 | \n", "1 | \n", "5 | \n", "2 | \n", "15 | \n", "14 | \n", "15 | \n", "Urban | \n", "5 to 10 hours | \n", "
4 | \n", "GP | \n", "F | \n", "16 | \n", "GT3 | \n", "T | \n", "3 | \n", "3 | \n", "1 | \n", "0 | \n", "no | \n", "... | \n", "2 | \n", "1 | \n", "2 | \n", "5 | \n", "4 | \n", "6 | \n", "10 | \n", "10 | \n", "Urban | \n", "2 to 5 hours | \n", "
5 rows × 29 columns
\n", "