Classwork 12
Data Visualization with seaborn
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
= pd.read_csv('https://bcdanl.github.io/data/beer_markets.csv') beer
- 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 bybrand
.
Answer:
Question 2
- Provide (1) seaborn code and (2) a simple comment to describe how the relationship between
log(price_per_floz)
andlog(beer_floz)
varies bybrand
.- Below adds
log(price_per_floz)
andlog(beer_floz)
to thebeer_mkt
DataFrame usingnumpy
’slog()
function:
- Below adds
import numpy as np
'log_price_per_floz'] = np.log( beer_mkt['price_per_floz'] )
beer_mkt['log_beer_floz'] = np.log( beer_mkt['beer_floz'] ) beer_mkt[
Answer:
Part 2
= pd.read_csv('https://bcdanl.github.io/data/stock_2023_2025.csv') stock
Question 3
- Provide (1) seaborn code and (2) a simple comment to describe how the daily trend of
Close
varies bycompany
.
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!