Classwork 12

Data Visualization with seaborn

Author

Byeong-Hak Choe

Published

April 25, 2025

Modified

April 30, 2025

Part 1

Direction



The dataset ,beer_markets.csv, (with its pathname https://bcdanl.github.io/data/beer_markets.csv) includes information about beer purchases across different markets, brands, and households.

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
beer = pd.read_csv('https://bcdanl.github.io/data/beer_markets.csv')


  • Each observation in beer is a household-level transaction record for a purchase of beer.

Variable Description

  • hh: an identifier of the household;
  • X_purchase_desc: details on the purchased item;
  • quantity: the number of items purchased;
  • brand: Bud Light, Busch Light, Coors Light, Miller Lite, or Natural Light;
  • dollar_spent: total dollar value of purchase;
  • beer_floz: total volume of beer, in fluid ounces;
  • price_per_floz: price per fl.oz. (i.e., beer spent/beer floz);
  • container: the type of container;
  • promo: Whether the item was promoted (coupon or otherwise);
  • market: Scan-track market (or state if rural);
  • demographic data, including gender, marital status, household income, class of work, race, education, age, the size of household, and whether or not the household has a microwave or a dishwasher.

Question 1

  • Provide (1) seaborn code and (2) a simple comment to describe how the distribution of price_per_floz varies by brand.

Answer:


Question 2

  • Provide (1) seaborn code and (2) a simple comment to describe how the relationship between log(price_per_floz) and log(beer_floz) varies by brand.
    • Below adds log(price_per_floz) and log(beer_floz) to the beer_mkt DataFrame using numpy’s log() function:
import numpy as np
beer_mkt['log_price_per_floz'] = np.log( beer_mkt['price_per_floz'] )
beer_mkt['log_beer_floz'] = np.log( beer_mkt['beer_floz'] )

Answer:




Part 2

stock = pd.read_csv('https://bcdanl.github.io/data/stock_2023_2025.csv')

Question 3

  • Provide (1) seaborn code and (2) a simple comment to describe how the daily trend of Close varies by company.

Answer:



Discussion

Welcome to our Classwork 12 Discussion Board! 👋

This space is designed for you to engage with your classmates about the material covered in Classwork 12.

Whether you are looking to delve deeper into the content, share insights, or have questions about the content, this is the perfect place for you.

If you have any specific questions for Byeong-Hak (@bcdanl) regarding the Classwork 12 materials or need clarification on any points, don’t hesitate to ask here.

Let’s collaborate and learn from each other!

Back to top