In [12]:
%matplotlib inline
import numpy as np
import pandas as pd
from scipy import stats, integrate
import matplotlib.pyplot as plt

import seaborn as sns

sns.set(color_codes=True)
sns.set_style("whitegrid")

np.random.seed(sum(map(ord, "distributions")))

In [13]:
tips = sns.load_dataset("tips")

In [14]:
g = sns.lmplot(x="total_bill",y="tip",hue="smoker", data=tips, palette="Set1")



In [15]:
g = sns.lmplot(x="total_bill", y="tip", col="day", hue="day", data=tips, col_wrap=2, size=3)



In [16]:
x = np.random.normal(size=100)
sns.distplot(x, kde=False, rug=True)


Out[16]:
<matplotlib.axes._subplots.AxesSubplot at 0x115cdb828>

In [17]:
sns.distplot(x, bins=20, kde=False, rug=True)


Out[17]:
<matplotlib.axes._subplots.AxesSubplot at 0x1160f0710>

In [18]:
x


Out[18]:
array([ 0.42852369,  1.19133255, -0.45820746, -1.85860798,  1.02445299,
        0.69330216,  0.78849804,  0.38978006,  0.28186484,  2.87595634,
       -0.47628215,  1.68025623, -0.39550873, -0.31309963, -1.08837344,
        1.35804163,  0.99799477, -1.56900497,  0.45547916, -1.21679124,
       -0.75801737, -0.07849588, -0.10971737,  0.81419187,  0.85226952,
        0.63110924, -0.00947497,  0.89289944,  1.38285579, -1.49399717,
        0.47088875, -0.01288971, -0.44335464,  2.14135081, -1.30731012,
        0.85712756, -1.33106341,  2.02990049,  0.4914988 ,  1.13272871,
        0.31018322, -0.68251238, -1.03515012,  0.92090423, -0.2528402 ,
        0.04264866,  0.12932479,  0.22791984,  0.27501328,  2.25623038,
        0.86225469,  0.83121643, -1.02652783, -0.57345982,  0.44343461,
       -0.23975428, -0.78221362,  0.9580867 ,  0.46108662, -0.03729805,
       -0.15460078,  0.68695857,  0.42026656, -0.19984644, -1.83236953,
       -0.6656998 , -1.31992855, -0.36497473,  0.17610984, -0.54795825,
       -0.52560693,  0.19350884, -0.93389106, -0.99318536, -0.38978803,
        0.0071343 ,  0.94001567,  1.1012718 , -0.05460403, -1.09726954,
        0.27576366, -0.6408722 , -0.04275091, -1.34058837, -0.91975866,
        0.0297272 ,  1.10771714, -0.59058897,  0.78724338, -0.1892485 ,
       -1.35383408, -0.32915806,  0.13750629,  0.03163861, -0.14147848,
        0.44890715,  0.5304522 ,  0.28049403,  1.40108737, -0.17444868])

In [19]:
len(x)


Out[19]:
100

In [20]:
type(x)


Out[20]:
numpy.ndarray

In [22]:
np.shape(x)


Out[22]:
(100,)

In [23]:
sns.kdeplot(x, shade=True)


Out[23]:
<matplotlib.axes._subplots.AxesSubplot at 0x1143dc208>

In [24]:
y = np.random.gamma(6, size=200)

In [25]:
sns.distplot(x, kde=False, fit=stats.gamma)


Out[25]:
<matplotlib.axes._subplots.AxesSubplot at 0x11574e048>

In [26]:
np.shape(y)


Out[26]:
(200,)

In [36]:
rs = np.random.RandomState(10)
f, axes = plt.subplots(2, 2, figsize=(7,7), sharex=True)
d = rs.normal(size=100)
sns.distplot(d, kde=False, color="b", ax=axes[0,0])
sns.distplot(d, hist=False, color="g", kde_kws={"shade":True}, ax=axes[1,0])
sns.distplot(d, hist=False, rug=True, color="r", ax=axes[0, 1])
sns.distplot(d, color="m", ax=axes[1, 1])
plt.setp(axes, yticks=[])
plt.tight_layout()



In [28]:




In [37]:
titan = pd.read_csv('../data/titanic/train.csv')

In [38]:
titan.head()


Out[38]:
PassengerId Survived Pclass Name Sex Age SibSp Parch Ticket Fare Cabin Embarked
0 1 0 3 Braund, Mr. Owen Harris male 22.0 1 0 A/5 21171 7.2500 NaN S
1 2 1 1 Cumings, Mrs. John Bradley (Florence Briggs Th... female 38.0 1 0 PC 17599 71.2833 C85 C
2 3 1 3 Heikkinen, Miss. Laina female 26.0 0 0 STON/O2. 3101282 7.9250 NaN S
3 4 1 1 Futrelle, Mrs. Jacques Heath (Lily May Peel) female 35.0 1 0 113803 53.1000 C123 S
4 5 0 3 Allen, Mr. William Henry male 35.0 0 0 373450 8.0500 NaN S

In [44]:
sns.distplot(titan['Fare'],kde=False)


Out[44]:
<matplotlib.axes._subplots.AxesSubplot at 0x116f32e10>

In [47]:
food = pd.read_csv('../data/food/openfood.tsv',sep='\t')


/usr/local/lib/python3.5/site-packages/IPython/core/interactiveshell.py:2717: DtypeWarning: Columns (0,3,5,27,36) have mixed types. Specify dtype option on import or set low_memory=False.
  interactivity=interactivity, compiler=compiler, result=result)

In [75]:
food.head(15)


Out[75]:
code url creator created_t created_datetime last_modified_t last_modified_datetime product_name generic_name quantity ... ph_100g fruits-vegetables-nuts_100g collagen-meat-protein-ratio_100g cocoa_100g chlorophyl_100g carbon-footprint_100g nutrition-score-fr_100g nutrition-score-uk_100g glycemic-index_100g water-hardness_100g
0 3087 http://world-en.openfoodfacts.org/product/0000... openfoodfacts-contributors 1474103866 2016-09-17T09:17:46Z 1474103893 2016-09-17T09:18:13Z Farine de blé noir NaN 1kg ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
1 24600 http://world-en.openfoodfacts.org/product/0000... date-limite-app 1434530704 2015-06-17T08:45:04Z 1434535914 2015-06-17T10:11:54Z Filet de bœuf NaN 2.46 kg ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2 27083 http://world-en.openfoodfacts.org/product/0000... canieatthis-app 1472223782 2016-08-26T15:03:02Z 1472223782 2016-08-26T15:03:02Z Marks % Spencer 2 Blueberry Muffins NaN 230g ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
3 27205 http://world-en.openfoodfacts.org/product/0000... tacinte 1458238630 2016-03-17T18:17:10Z 1458238638 2016-03-17T18:17:18Z NaN NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
4 36252 http://world-en.openfoodfacts.org/product/0000... tacinte 1422221701 2015-01-25T21:35:01Z 1422221855 2015-01-25T21:37:35Z Lion Peanut x2 NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
5 39259 http://world-en.openfoodfacts.org/product/0000... tacinte 1422221773 2015-01-25T21:36:13Z 1473538082 2016-09-10T20:08:02Z Twix x2 NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
6 39529 http://world-en.openfoodfacts.org/product/0000... teolemon 1420147051 2015-01-01T21:17:31Z 1473538082 2016-09-10T20:08:02Z Pack de 2 Twix NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
7 50913 http://world-en.openfoodfacts.org/product/0000... canieatthis-app 1483186707 2016-12-31T12:18:27Z 1483186708 2016-12-31T12:18:28Z M&S Extrenely Chocolatey Milk, Dark & White Ch... NaN 500g ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
8 56434 http://world-en.openfoodfacts.org/product/0000... canieatthis-app 1468005372 2016-07-08T19:16:12Z 1468005372 2016-07-08T19:16:12Z diet lemonade by Sainsbury's NaN 2l ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
9 290616 http://world-en.openfoodfacts.org/product/0000... b7 1484605978 2017-01-16T22:32:58Z 1484606542 2017-01-16T22:42:22Z Salade Cesar Laitue en salade 0.980 kg ... NaN NaN NaN NaN NaN NaN 6.0 6.0 NaN NaN
10 394710 http://world-en.openfoodfacts.org/product/0000... b7 1484497370 2017-01-15T16:22:50Z 1484501040 2017-01-15T17:24:00Z Danoises à la cannelle roulées Pâtisserie 1.150 kg ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
11 673358 http://world-en.openfoodfacts.org/product/0000... canieatthis-app 1483117649 2016-12-30T17:07:29Z 1483117649 2016-12-30T17:07:29Z Veggie Colin the Caterpillar NaN 170g ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
12 1071894 http://world-en.openfoodfacts.org/product/0000... bcatelin 1409411252 2014-08-30T15:07:32Z 1461437669 2016-04-23T18:54:29Z Flute Flute NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
13 1471762 http://world-en.openfoodfacts.org/product/0000... canieatthis-app 1470247218 2016-08-03T18:00:18Z 1470247218 2016-08-03T18:00:18Z still Scottish water NaN NaN ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
14 1798180 http://world-en.openfoodfacts.org/product/0000... canieatthis-app 1468171601 2016-07-10T17:26:41Z 1468171601 2016-07-10T17:26:41Z Fairtrade Ground Cinnamon NaN 45g ... NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN

15 rows × 161 columns


In [76]:
z = [x for x in food['quantity']]
print(type(z[0]))


<class 'str'>

In [54]:
food_carbon = [food['carbon-footprint_100g'] if food['carbon-footprint_100g']!= NaN]


  File "<ipython-input-54-d88954cfdd0a>", line 1
    food_carbon = [food['carbon-footprint_100g'] if food['carbon-footprint_100g'] != NaN]
                                                                                        ^
SyntaxError: invalid syntax

In [55]:
x = [1,2,3]

In [64]:
y = [z*3 for z in x if z != 2]

In [65]:
y


Out[65]:
[3, 9]

In [66]:
for yy in y:
    print(yy)


3
9

In [ ]: