forked from jmportilla/DAT8
-
Notifications
You must be signed in to change notification settings - Fork 0
/
08_pandas_review_nb.py
72 lines (41 loc) · 1.06 KB
/
08_pandas_review_nb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# # Pandas Review
import pandas as pd
url = 'https://raw.githubusercontent.com/justmarkham/DAT8/master/data/drinks.csv'
df = pd.read_csv(url).head(5).copy()
df
# For each of the following lines of code:
#
# - What the **data type** of the object that is returned?
# - What is the **shape** of the object that is returned?
#
#
# 1. `df`
# 2. `df.continent`
# 3. `df['continent']`
# 4. `df[['country', 'continent']]`
# 5. `df[[False, True, False, True, False]]`
# ## Question 1
df
print type(df)
print df.shape
# ## Question 2
df.continent
print type(df.continent)
print df.continent.shape
# ## Question 3
df['continent']
print type(df['continent'])
print df['continent'].shape
# ## Question 4
df[['country', 'continent']]
print type(df[['country', 'continent']])
print df[['country', 'continent']].shape
# equivalent
cols = ['country', 'continent']
df[cols]
# ## Question 5
df[[False, True, False, True, False]]
print type(df[[False, True, False, True, False]])
print df[[False, True, False, True, False]].shape
# equivalent
df[df.continent=='EU']