Accompanies post on Practical Business Python
In [1]:
import pandas as pd
import seaborn as sns
import plotly.express as px
In [2]:
%matplotlib inline
In [3]:
sns.set_style('whitegrid')
In [4]:
df_beers = pd.read_csv('https://github.com/nickhould/craft-beers-dataset/blob/master/data/processed/beers.csv?raw=True', index_col=0)
df_breweries = pd.read_csv('https://github.com/nickhould/craft-beers-dataset/blob/master/data/processed/breweries.csv?raw=True', index_col=0)
In [5]:
df_beers.head()
Out[5]:
In [6]:
df_beers.info()
In [7]:
df_breweries.head()
Out[7]:
In [8]:
df_breweries.info()
In [9]:
all_beer = pd.merge(df_beers, df_breweries, how='left',
left_on="brewery_id",
right_on="id",
suffixes=('_beer', '_brewery'))
In [10]:
all_beer.head()
Out[10]:
Check for empty values
In [11]:
all_beer.isna().sum()
Out[11]:
In [12]:
all_beer.info()
In [13]:
all_beer['ounces'].plot(kind='hist')
Out[13]:
In [14]:
all_beer['style'].value_counts()
Out[14]:
In [15]:
all_beer['IPA'] = all_beer['style'].str.contains('IPA', case=False)
In [16]:
all_beer['IPA'].value_counts()
Out[16]:
In [17]:
sns.catplot(data=all_beer, x='IPA', y='ibu', kind='box')
Out[17]:
In [18]:
sns.catplot(data=all_beer, x='IPA', y='ibu', kind='swarm')
Out[18]:
In [19]:
fig = px.scatter(all_beer, x="abv", y="ibu")
fig.show()
In [20]:
fig = px.scatter(all_beer, x="abv", y="ibu", color='state', hover_name='name_beer')
fig.show()
In [21]:
fig = px.scatter(all_beer, x="abv", y="ibu", color='state', hover_name='name_beer')
fig.show()
In [23]:
mn_beer = all_beer[all_beer['state'].str.contains('MN')].copy()
In [24]:
fig = px.scatter(mn_beer, x="abv", y="ibu", color='state', hover_name='name_beer', hover_data=['name_brewery'])
fig.show()
In [ ]: