{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "# Visualizing a Categorical and a Quantitative Variable\n", "> Categorical variables are present in nearly every dataset, but they are especially prominent in survey data. In this chapter, you will learn how to create and customize categorical plots such as box plots, bar plots, count plots, and point plots. Along the way, you will explore survey data from young people about their interests, students about their study habits, and adult men about their feelings about masculinity. 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: images/school_pointplot.png" ] }, { "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": [ "# Count plots and bar plots\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Count plots\n", "In this exercise, we'll return to exploring our dataset that contains the responses to a survey sent out to young people. We might suspect that young people spend a lot of time on the internet, but how much do they report using the internet each day? Let's use a count plot to break down the number of survey responses in each category and then explore whether it changes based on age." ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | Music | \n", "Techno | \n", "Movies | \n", "History | \n", "Mathematics | \n", "Pets | \n", "Spiders | \n", "Loneliness | \n", "Parents' advice | \n", "Internet usage | \n", "Finances | \n", "Age | \n", "Siblings | \n", "Gender | \n", "Village - town | \n", "Age Category | \n", "Interested in Math | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "5.0 | \n", "1.0 | \n", "5.0 | \n", "1.0 | \n", "3.0 | \n", "4.0 | \n", "1.0 | \n", "3.0 | \n", "4.0 | \n", "few hours a day | \n", "3.0 | \n", "20.0 | \n", "1.0 | \n", "female | \n", "village | \n", "Less than 21 | \n", "False | \n", "
1 | \n", "4.0 | \n", "1.0 | \n", "5.0 | \n", "1.0 | \n", "5.0 | \n", "5.0 | \n", "1.0 | \n", "2.0 | \n", "2.0 | \n", "few hours a day | \n", "3.0 | \n", "19.0 | \n", "2.0 | \n", "female | \n", "city | \n", "Less than 21 | \n", "True | \n", "
2 | \n", "5.0 | \n", "1.0 | \n", "5.0 | \n", "1.0 | \n", "5.0 | \n", "5.0 | \n", "1.0 | \n", "5.0 | \n", "3.0 | \n", "few hours a day | \n", "2.0 | \n", "20.0 | \n", "2.0 | \n", "female | \n", "city | \n", "Less than 21 | \n", "True | \n", "
3 | \n", "5.0 | \n", "2.0 | \n", "5.0 | \n", "4.0 | \n", "4.0 | \n", "1.0 | \n", "5.0 | \n", "5.0 | \n", "2.0 | \n", "most of the day | \n", "2.0 | \n", "22.0 | \n", "1.0 | \n", "female | \n", "city | \n", "21+ | \n", "True | \n", "
4 | \n", "5.0 | \n", "2.0 | \n", "5.0 | \n", "3.0 | \n", "2.0 | \n", "1.0 | \n", "1.0 | \n", "3.0 | \n", "3.0 | \n", "few hours a day | \n", "4.0 | \n", "20.0 | \n", "1.0 | \n", "female | \n", "village | \n", "Less than 21 | \n", "False | \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", "