IST 718 | WK 2 | ASYNC

In [83]:
import pandas as pd 
import matplotlib.pyplot as plt
import seaborn as sns
dodgers = pd.read_csv("dodgers.csv")
In [84]:
dodgers.head()
Out[84]:
month day attend day_of_week opponent temp skies day_night cap shirt fireworks bobblehead
0 APR 10 56000 Tuesday Pirates 67 Clear Day NO NO NO NO
1 APR 11 29729 Wednesday Pirates 58 Cloudy Night NO NO NO NO
2 APR 12 28328 Thursday Pirates 57 Cloudy Night NO NO NO NO
3 APR 13 31601 Friday Padres 54 Cloudy Night NO NO YES NO
4 APR 14 46549 Saturday Padres 57 Cloudy Night NO NO NO NO
In [85]:
sns.boxplot(x="day_of_week", y="attend", data=dodgers, color="gray", 
            order=["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"])
plt.xticks(rotation="vertical")
Out[85]:
(array([0, 1, 2, 3, 4, 5, 6]), <a list of 7 Text xticklabel objects>)
In [86]:
dodgers['attend'].max()
Out[86]:
56000
In [87]:
dodgers['attend_norm'] = dodgers.apply(lambda x: x['attend']/56000, axis=1)
In [88]:
dodgers['attend_n2'] = (dodgers['attend']/56000)*100
In [89]:
set(dodgers['opponent'].values)
Out[89]:
{'Angels',
 'Astros',
 'Braves',
 'Brewers',
 'Cardinals',
 'Cubs',
 'Giants',
 'Marlins',
 'Mets',
 'Nationals',
 'Padres',
 'Phillies',
 'Pirates',
 'Reds',
 'Rockies',
 'Snakes',
 'White Sox'}
In [90]:
dodgers['opponent'].value_counts()
Out[90]:
Rockies      9
Giants       9
Snakes       9
Padres       9
Cardinals    7
Mets         4
Brewers      4
Marlins      3
Reds         3
Cubs         3
Braves       3
Pirates      3
Nationals    3
Angels       3
White Sox    3
Phillies     3
Astros       3
Name: opponent, dtype: int64
In [91]:
sns.regplot(x="temp", y="attend_n2", data=dodgers);
In [92]:
sns.scatterplot(x="temp", y="attend_n2", hue="day_of_week", size="skies", palette="Set2", data=dodgers)
Out[92]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1ab7d4d0>
In [93]:
sns.scatterplot(x="temp", y="attend_n2", hue="bobblehead", size="skies", palette="Set2", data=dodgers)
Out[93]:
<matplotlib.axes._subplots.AxesSubplot at 0x1a1ac22250>
In [94]:
with sns.plotting_context("paper"):
    sns.scatterplot(x="temp", y="attend", hue="day_of_week", size="skies", palette="Set2", data=dodgers)
    plt.title('Attend by Temp')
In [95]:
sns.lmplot(x="temp", y="attend_n2", col="day_of_week", col_wrap=3, data=dodgers);
In [ ]:
 
In [ ]: