<jupyter_start><jupyter_text>Lambda School Data Science*Unit 1, Sprint 1, Module 1*---  A FIRST LOOK AT DATA ASSIGNMENT  Assignment - now it's your turnPick at least one Python DS library, and using documentation/examples reproduce in this notebook something cool. It's OK if you don't fully understand it or get it 100% working, but do put in effort and look things up.  Assignment questionsAfter you've worked on some code, answer the following questions in this text block:1.  Describe in a paragraph of text what you did and why, as if you were writing an email to somebody interested but nontechnical.2.  What was the most challenging part of what you did?3.  What was the most interesting thing you learned?4.  What area would you like to explore with more time?<jupyter_code># import the libraries that will be used.
import numpy as np 
import pandas as pd 
import seaborn as sns 
import matplotlib.pyplot as plt
# using same data set from lecture.

# radin the .csv file.
drinks = pd.read_csv('https://raw.githubusercontent.com/fivethirtyeight/data/master/alcohol-consumption/drinks.csv')
# print the shape of the data frame.
print(drinks.shape)
# show the data frame with headers.
drinks.head()
# look at all the column names.
drinks.columns
# list the rows in non ascending order by 'wine_servings'.
drinks.sort_values('wine_servings', ascending=False).head(10)
# show the statistics for the 'wine_servings' column.
drinks['wine_servings'].describe()
# show the largest 10 values in the 'wine_servings' column.
drinks.nlargest(10, 'wine_servings')
# create a histogram of the 'wine_servings' column.
drinks.wine_servings.hist()
# show the histrogram.
plt.show()
# add a column at the end to give some text to the 'wine_servings' score.
drinks['drinks_wine'] = np.where(drinks['wine_servings'] > 300, 'high',
                           np.where(drinks['wine_servings'] >= 150, 'medium',
                           np.where(drinks['wine_servings'] == 0, 'none', 'low')))
                        
# show the headers of the data set.
drinks.head()
# show the new values for the new 'drinks_wine' column.
drinks.drinks_wine.value_counts()<jupyter_output><empty_output><jupyter_text>Joining Another Dataset<jupyter_code># join the countries data set from lecture.

# label and read in the .csv file.
countries = pd.read_csv('https://raw.githubusercontent.com/lukes/ISO-3166-Countries-with-Regional-Codes/master/all/all.csv')
# show the columns of the data frame we want to merge.
countries[['name','region','sub-region']].head()
# use pd.merge to merge the data sets together, selecting the columns that we want to merge.
df = pd.merge(drinks, countries[['name','region','sub-region']], how='left', left_on='country', right_on='name')
# show the shape of the data frame.
print(df.shape)
# show the data frame with headers.
df.head()
# show how many NA values there are and where.
df.isna().sum()
# show which countries did not join properly and have an NA.
df[df.region.isna()]
# look specifically at 'Czech Republic'.
drinks.iloc[45]
# show the value counts for the 'region' column.
df.region.value_counts()
# use group by and create a bar plot with 'sub_region' and 'wine_servings' columns, enlarge the garph with figsize.
df.groupby('sub-region').wine_servings.mean().plot(kind='bar', figsize=(20,6))
# give the graph a title.
plt.title('Average Wine Servings by Region')
# label the y axis.
plt.ylabel('Wine Servings')
# show the bar plot.
plt.show()
# create a boxplot for columns 'wine_servings' and 'region'.
df.boxplot(column='wine_servings', by='region', figsize=(10,6))
# show the box plot.
plt.show()
# create a pairplot with 'wine_servings' as x axis and 'spirit_servings' as y axis, and color the data based on the 'region' column.
sns.pairplot(x_vars=["wine_servings"], y_vars=["spirit_servings"], data=df, hue="region", height=8)
# show the pair plot.
plt.show()<jupyter_output><empty_output><jupyter_text>Awesome Bokeh Plot<jupyter_code>.# drop rows with NAs for Bokeh Interactive plot
df = df.dropna(subset=["region"])
# show the new shape of the data set with the dropped rows.
df.shape
# Bokeh plot code.
from bokeh.io import output_file, show, output_notebook
from bokeh.models import ColumnDataSource, HoverTool, CategoricalColorMapper
from bokeh.palettes import d3
from bokeh.plotting import figure
from bokeh.transform import transform
output_notebook()

x = df.wine_servings.values
y = df.spirit_servings.values
country = df.country
region = df.region

source = ColumnDataSource(data=dict(x=x, y=y, country=country, region=region))
hover = HoverTool(tooltips=[
    ("index", "$index"),
    ("(x,y)", "(@x, @y)"),
    ('country', '@country'),
])

palette = d3['Category10'][len(df['region'].unique())]
mapper = CategoricalColorMapper(factors = df['region'].unique(), palette = palette)
# create figure and plot.
p = figure(plot_width=600, plot_height=600, 
           tools=[hover, "wheel_zoom", "box_zoom", "reset"], 
           title="Wine and Spirit Servings per Year by Country")
# create plot.
p.scatter(x='x', y='y', size=10, alpha=0.8,
          color={'field': 'region', 'transform': mapper},
          legend='region', 
          source=source)
# add axis labels.
p.xaxis.axis_label = "Wine Servings"
p.yaxis.axis_label = "Spirit Servings"

output_file('interactive_bokeh_plot.html')
show(p)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11797647937278327, 'fraction_numerical': 0.009333582228859437, 'mean_word_length': 4.657866948257656, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '396823', 'license': 'MIT', 'n_tokens_mistral': 1767, 'n_tokens_neox': 1682, 'n_words': 582, 'path': 'module1-afirstlookatdata/1.Assignment/1.Assignment_AFirstLookatData.ipynb', 'repo_name': 'CVanchieri/DS-Unit1-Sprint1-DealingWithData', 'size': '5357'}