In [16]:
from sklearn import datasets

In [17]:
iris = datasets.load_iris()

In [18]:
animals = ['cat', 'dog', 'monkey']
for idx, animal in enumerate(animals):
    print('#{}: {}'.format(idx + 1, animal))


#1: cat
#2: dog
#3: monkey

In [19]:
x = [x for x in range(10) if x % 2 == 0]

In [20]:
x


Out[20]:
[0, 2, 4, 6, 8]

In [21]:
d = {(x,x+1) for x in range(30)}

In [22]:
d


Out[22]:
{(0, 1),
 (1, 2),
 (2, 3),
 (3, 4),
 (4, 5),
 (5, 6),
 (6, 7),
 (7, 8),
 (8, 9),
 (9, 10),
 (10, 11),
 (11, 12),
 (12, 13),
 (13, 14),
 (14, 15),
 (15, 16),
 (16, 17),
 (17, 18),
 (18, 19),
 (19, 20),
 (20, 21),
 (21, 22),
 (22, 23),
 (23, 24),
 (24, 25),
 (25, 26),
 (26, 27),
 (27, 28),
 (28, 29),
 (29, 30)}

In [23]:
import numpy as np

In [24]:
a = np.array([1,2,3])

In [25]:
type(a)


Out[25]:
numpy.ndarray

In [26]:
a.strides


Out[26]:
(4,)

In [27]:
b = np.array([[1,2,3],[3,5,6]])

In [28]:
b.shape


Out[28]:
(2, 3)

In [29]:
c = np.eye(3)

In [30]:
c.ndim


Out[30]:
2

In [31]:
np.full((4,7),7)


Out[31]:
array([[7, 7, 7, 7, 7, 7, 7],
       [7, 7, 7, 7, 7, 7, 7],
       [7, 7, 7, 7, 7, 7, 7],
       [7, 7, 7, 7, 7, 7, 7]])

In [32]:
np.ones((3,4))


Out[32]:
array([[ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.],
       [ 1.,  1.,  1.,  1.]])

In [33]:
k = np.random.random((2,3,4,3,5,5))

In [34]:
k.ndim


Out[34]:
6

In [35]:
k.shape


Out[35]:
(2, 3, 4, 3, 5, 5)

In [36]:
k.size


Out[36]:
1800

In [37]:
k.itemsize


Out[37]:
8

In [38]:
k.strides


Out[38]:
(7200, 2400, 600, 200, 40, 8)

In [39]:
np.pi


Out[39]:
3.141592653589793

In [40]:
import pandas as pd
import matplotlib.pyplot as plot
from matplotlib import style
style.use("ggplot")

In [41]:
url = 'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/chipotle.tsv'
    
df = pd.read_csv(url, sep = '\t')

In [42]:
df.head(5)


Out[42]:
order_id quantity item_name choice_description item_price
0 1 1 Chips and Fresh Tomato Salsa NaN $2.39
1 1 1 Izze [Clementine] $3.39
2 1 1 Nantucket Nectar [Apple] $3.39
3 1 1 Chips and Tomatillo-Green Chili Salsa NaN $2.39
4 2 2 Chicken Bowl [Tomatillo-Red Chili Salsa (Hot), [Black Beans... $16.98

In [43]:
df['item_name'].value_counts().head(1)


Out[43]:
Chicken Bowl    726
Name: item_name, dtype: int64

In [44]:
df.shape


Out[44]:
(4622, 5)

In [45]:
df.columns


Out[45]:
Index(['order_id', 'quantity', 'item_name', 'choice_description',
       'item_price'],
      dtype='object')

In [46]:
s = pd.Series(np.random.randn(5),index = ['a','b','c','d','e'])

In [47]:
s


Out[47]:
a    0.804146
b    1.509363
c    1.100273
d    0.271942
e    1.192606
dtype: float64

In [48]:
# df['item_price'].plot()
# plt.show()
df.info


Out[48]:
<bound method DataFrame.info of       order_id  quantity                              item_name  \
0            1         1           Chips and Fresh Tomato Salsa   
1            1         1                                   Izze   
2            1         1                       Nantucket Nectar   
3            1         1  Chips and Tomatillo-Green Chili Salsa   
4            2         2                           Chicken Bowl   
5            3         1                           Chicken Bowl   
6            3         1                          Side of Chips   
7            4         1                          Steak Burrito   
8            4         1                       Steak Soft Tacos   
9            5         1                          Steak Burrito   
10           5         1                    Chips and Guacamole   
11           6         1                   Chicken Crispy Tacos   
12           6         1                     Chicken Soft Tacos   
13           7         1                           Chicken Bowl   
14           7         1                    Chips and Guacamole   
15           8         1  Chips and Tomatillo-Green Chili Salsa   
16           8         1                        Chicken Burrito   
17           9         1                        Chicken Burrito   
18           9         2                            Canned Soda   
19          10         1                           Chicken Bowl   
20          10         1                    Chips and Guacamole   
21          11         1                       Barbacoa Burrito   
22          11         1                       Nantucket Nectar   
23          12         1                        Chicken Burrito   
24          12         1                                   Izze   
25          13         1           Chips and Fresh Tomato Salsa   
26          13         1                           Chicken Bowl   
27          14         1                       Carnitas Burrito   
28          14         1                            Canned Soda   
29          15         1                        Chicken Burrito   
...        ...       ...                                    ...   
4592      1825         1                       Barbacoa Burrito   
4593      1825         1                          Carnitas Bowl   
4594      1825         1                          Barbacoa Bowl   
4595      1826         1                           Chicken Bowl   
4596      1826         1                    Chips and Guacamole   
4597      1826         1                      Canned Soft Drink   
4598      1826         1                          Bottled Water   
4599      1827         1                           Chicken Bowl   
4600      1827         1                    Chips and Guacamole   
4601      1827         1                      Canned Soft Drink   
4602      1827         1                       Barbacoa Burrito   
4603      1827         1                       Barbacoa Burrito   
4604      1828         1                           Chicken Bowl   
4605      1828         1                    Chips and Guacamole   
4606      1828         1                      Canned Soft Drink   
4607      1829         1                          Steak Burrito   
4608      1829         1                         Veggie Burrito   
4609      1829         1                      Canned Soft Drink   
4610      1830         1                          Steak Burrito   
4611      1830         1                         Veggie Burrito   
4612      1831         1                          Carnitas Bowl   
4613      1831         1                                  Chips   
4614      1831         1                          Bottled Water   
4615      1832         1                     Chicken Soft Tacos   
4616      1832         1                    Chips and Guacamole   
4617      1833         1                          Steak Burrito   
4618      1833         1                          Steak Burrito   
4619      1834         1                     Chicken Salad Bowl   
4620      1834         1                     Chicken Salad Bowl   
4621      1834         1                     Chicken Salad Bowl   

                                     choice_description item_price  
0                                                   NaN     $2.39   
1                                          [Clementine]     $3.39   
2                                               [Apple]     $3.39   
3                                                   NaN     $2.39   
4     [Tomatillo-Red Chili Salsa (Hot), [Black Beans...    $16.98   
5     [Fresh Tomato Salsa (Mild), [Rice, Cheese, Sou...    $10.98   
6                                                   NaN     $1.69   
7     [Tomatillo Red Chili Salsa, [Fajita Vegetables...    $11.75   
8     [Tomatillo Green Chili Salsa, [Pinto Beans, Ch...     $9.25   
9     [Fresh Tomato Salsa, [Rice, Black Beans, Pinto...     $9.25   
10                                                  NaN     $4.45   
11    [Roasted Chili Corn Salsa, [Fajita Vegetables,...     $8.75   
12    [Roasted Chili Corn Salsa, [Rice, Black Beans,...     $8.75   
13    [Fresh Tomato Salsa, [Fajita Vegetables, Rice,...    $11.25   
14                                                  NaN     $4.45   
15                                                  NaN     $2.39   
16    [Tomatillo-Green Chili Salsa (Medium), [Pinto ...     $8.49   
17    [Fresh Tomato Salsa (Mild), [Black Beans, Rice...     $8.49   
18                                             [Sprite]     $2.18   
19    [Tomatillo Red Chili Salsa, [Fajita Vegetables...     $8.75   
20                                                  NaN     $4.45   
21    [[Fresh Tomato Salsa (Mild), Tomatillo-Green C...     $8.99   
22                                 [Pomegranate Cherry]     $3.39   
23    [[Tomatillo-Green Chili Salsa (Medium), Tomati...    $10.98   
24                                         [Grapefruit]     $3.39   
25                                                  NaN     $2.39   
26    [Roasted Chili Corn Salsa (Medium), [Pinto Bea...     $8.49   
27    [[Tomatillo-Green Chili Salsa (Medium), Roaste...     $8.99   
28                                         [Dr. Pepper]     $1.09   
29    [Tomatillo-Green Chili Salsa (Medium), [Pinto ...     $8.49   
...                                                 ...        ...  
4592  [Tomatillo Red Chili Salsa, [Rice, Fajita Vege...    $11.75   
4593  [Roasted Chili Corn Salsa, [Rice, Sour Cream, ...    $11.75   
4594  [Roasted Chili Corn Salsa, [Pinto Beans, Sour ...    $11.75   
4595  [Tomatillo Green Chili Salsa, [Rice, Black Bea...     $8.75   
4596                                                NaN     $4.45   
4597                                           [Nestea]     $1.25   
4598                                                NaN     $1.50   
4599      [Roasted Chili Corn Salsa, [Cheese, Lettuce]]     $8.75   
4600                                                NaN     $4.45   
4601                                        [Diet Coke]     $1.25   
4602                      [Tomatillo Green Chili Salsa]     $9.25   
4603                      [Tomatillo Green Chili Salsa]     $9.25   
4604  [Fresh Tomato Salsa, [Rice, Black Beans, Chees...     $8.75   
4605                                                NaN     $4.45   
4606                                             [Coke]     $1.25   
4607  [Tomatillo Green Chili Salsa, [Rice, Cheese, S...    $11.75   
4608  [Tomatillo Red Chili Salsa, [Fajita Vegetables...    $11.25   
4609                                           [Sprite]     $1.25   
4610  [Fresh Tomato Salsa, [Rice, Sour Cream, Cheese...    $11.75   
4611  [Tomatillo Green Chili Salsa, [Rice, Fajita Ve...    $11.25   
4612  [Fresh Tomato Salsa, [Fajita Vegetables, Rice,...     $9.25   
4613                                                NaN     $2.15   
4614                                                NaN     $1.50   
4615   [Fresh Tomato Salsa, [Rice, Cheese, Sour Cream]]     $8.75   
4616                                                NaN     $4.45   
4617  [Fresh Tomato Salsa, [Rice, Black Beans, Sour ...    $11.75   
4618  [Fresh Tomato Salsa, [Rice, Sour Cream, Cheese...    $11.75   
4619  [Fresh Tomato Salsa, [Fajita Vegetables, Pinto...    $11.25   
4620  [Fresh Tomato Salsa, [Fajita Vegetables, Lettu...     $8.75   
4621  [Fresh Tomato Salsa, [Fajita Vegetables, Pinto...     $8.75   

[4622 rows x 5 columns]>

In [49]:
df.apply(pd.to_numeric,errors='ignore').info()


<class 'pandas.core.frame.DataFrame'>
RangeIndex: 4622 entries, 0 to 4621
Data columns (total 5 columns):
order_id              4622 non-null int64
quantity              4622 non-null int64
item_name             4622 non-null object
choice_description    3376 non-null object
item_price            4622 non-null object
dtypes: int64(2), object(3)
memory usage: 180.6+ KB

In [61]:
df['quantity'].plot(kind="bar")


Out[61]:
<matplotlib.axes._subplots.AxesSubplot at 0x14ae91a5978>

In [62]:
plot.show()



In [60]:
import quandl

In [ ]:


In [ ]:


In [ ]: