3. Grading review, Pandas, and Iterables#
3.1. Grading Calculation#
here is my solution
def compute_grade(num_level1,num_level2,num_level3):
'''
Computes a grade for CSC/DSP310 from numbers of achievements at each level
Parameters:
------------
num_level1 : int
number of level 1 achievements earned
num_level2 : int
number of level 2 achievements earned
num_level3 : int
number of level 3 achievements earned
Returns:
--------
letter_grade : string
letter grade with modifier (+/-)
'''
if num_level1 == 15:
if num_level2 == 15:
if num_level3 == 15:
grade = 'A'
elif num_level3 >= 10:
grade = 'A-'
elif num_level3 >=5:
grade = 'B+'
else:
grade = 'B'
elif num_level2 >=10:
grade = 'B-'
elif num_level2 >=5:
grade = 'C+'
else:
grade = 'C'
elif num_level1 >= 10:
grade = 'C-'
elif num_level1 >= 5:
grade = 'D+'
elif num_level1 >=3:
grade = 'D'
else:
grade = 'F'
return grade
Note that we can verify it works using assert
assert compute_grade(15,15,15) =='A'
assert compute_grade(15,15,9) =='B+'
this also means we can assign the value out
my_grade = compute_grade(15,11,5)
my_grade
'B-'
Alternatively if we use a side effect instead, printing the value instead of returning it.
def compute_grade_sideeffect(num_level1,num_level2,num_level3):
'''
Computes a grade for CSC/DSP310 from numbers of achievements at each level
Parameters:
------------
num_level1 : int
number of level 1 achievements earned
num_level2 : int
number of level 2 achievements earned
num_level3 : int
number of level 3 achievements earned
Returns:
--------
letter_grade : string
letter grade with modifier (+/-)
'''
if num_level1 == 15:
if num_level2 == 15:
if num_level3 == 15:
grade = 'A'
elif num_level3 >= 10:
grade = 'A-'
elif num_level3 >=5:
grade = 'B+'
else:
grade = 'B'
elif num_level2 >=10:
grade = 'B-'
elif num_level2 >=5:
grade = 'C+'
else:
grade = 'C'
elif num_level1 >= 10:
grade = 'C-'
elif num_level1 >= 5:
grade = 'D+'
elif num_level1 >=3:
grade = 'D'
else:
grade = 'F'
print( grade)
Look this way it looks similar:
compute_grade_sideeffect(15,15,15)
A
compute_grade(15,15,15)
'A'
and python lets us assign something
my_grade = compute_grade_sideeffect(15,15,15)
A
but the output is nothing
type(my_grade)
NoneType
3.2. Loading data with Pandas#
First we learned about the dataset then we can load it.
coffee_data_url = 'https://raw.githubusercontent.com/jldbc/coffee-quality-database/master/data/robusta_data_cleaned.csv'
We will use pandas.
import pandas as pd
load the data
coffee_df = pd.read_csv(coffee_data_url,index_col=0)
type(coffee_df)
pandas.core.frame.DataFrame
coffee_df.columns
Index(['Species', 'Owner', 'Country.of.Origin', 'Farm.Name', 'Lot.Number',
'Mill', 'ICO.Number', 'Company', 'Altitude', 'Region', 'Producer',
'Number.of.Bags', 'Bag.Weight', 'In.Country.Partner', 'Harvest.Year',
'Grading.Date', 'Owner.1', 'Variety', 'Processing.Method',
'Fragrance...Aroma', 'Flavor', 'Aftertaste', 'Salt...Acid',
'Bitter...Sweet', 'Mouthfeel', 'Uniform.Cup', 'Clean.Cup', 'Balance',
'Cupper.Points', 'Total.Cup.Points', 'Moisture', 'Category.One.Defects',
'Quakers', 'Color', 'Category.Two.Defects', 'Expiration',
'Certification.Body', 'Certification.Address', 'Certification.Contact',
'unit_of_measurement', 'altitude_low_meters', 'altitude_high_meters',
'altitude_mean_meters'],
dtype='object')
coffee_df.columns[0]
'Species'
len(coffee_df.columns)
43
coffee_df.shape
(28, 43)
coffee_df.head()
Species | Owner | Country.of.Origin | Farm.Name | Lot.Number | Mill | ICO.Number | Company | Altitude | Region | ... | Color | Category.Two.Defects | Expiration | Certification.Body | Certification.Address | Certification.Contact | unit_of_measurement | altitude_low_meters | altitude_high_meters | altitude_mean_meters | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Robusta | ankole coffee producers coop | Uganda | kyangundu cooperative society | NaN | ankole coffee producers | 0 | ankole coffee producers coop | 1488 | sheema south western | ... | Green | 2 | June 26th, 2015 | Uganda Coffee Development Authority | e36d0270932c3b657e96b7b0278dfd85dc0fe743 | 03077a1c6bac60e6f514691634a7f6eb5c85aae8 | m | 1488.0 | 1488.0 | 1488.0 |
2 | Robusta | nishant gurjer | India | sethuraman estate kaapi royale | 25 | sethuraman estate | 14/1148/2017/21 | kaapi royale | 3170 | chikmagalur karnataka indua | ... | NaN | 2 | October 31st, 2018 | Specialty Coffee Association | ff7c18ad303d4b603ac3f8cff7e611ffc735e720 | 352d0cf7f3e9be14dad7df644ad65efc27605ae2 | m | 3170.0 | 3170.0 | 3170.0 |
3 | Robusta | andrew hetzel | India | sethuraman estate | NaN | NaN | 0000 | sethuraman estate | 1000m | chikmagalur | ... | Green | 0 | April 29th, 2016 | Specialty Coffee Association | ff7c18ad303d4b603ac3f8cff7e611ffc735e720 | 352d0cf7f3e9be14dad7df644ad65efc27605ae2 | m | 1000.0 | 1000.0 | 1000.0 |
4 | Robusta | ugacof | Uganda | ugacof project area | NaN | ugacof | 0 | ugacof ltd | 1212 | central | ... | Green | 7 | July 14th, 2015 | Uganda Coffee Development Authority | e36d0270932c3b657e96b7b0278dfd85dc0fe743 | 03077a1c6bac60e6f514691634a7f6eb5c85aae8 | m | 1212.0 | 1212.0 | 1212.0 |
5 | Robusta | katuka development trust ltd | Uganda | katikamu capca farmers association | NaN | katuka development trust | 0 | katuka development trust ltd | 1200-1300 | luwero central region | ... | Green | 3 | June 26th, 2015 | Uganda Coffee Development Authority | e36d0270932c3b657e96b7b0278dfd85dc0fe743 | 03077a1c6bac60e6f514691634a7f6eb5c85aae8 | m | 1200.0 | 1300.0 | 1250.0 |
5 rows × 43 columns
coffee_df.head
<bound method NDFrame.head of Species Owner Country.of.Origin
1 Robusta ankole coffee producers coop Uganda \
2 Robusta nishant gurjer India
3 Robusta andrew hetzel India
4 Robusta ugacof Uganda
5 Robusta katuka development trust ltd Uganda
6 Robusta andrew hetzel India
7 Robusta andrew hetzel India
8 Robusta nishant gurjer India
9 Robusta nishant gurjer India
10 Robusta ugacof Uganda
11 Robusta ugacof Uganda
12 Robusta nishant gurjer India
13 Robusta andrew hetzel India
14 Robusta kasozi coffee farmers association Uganda
15 Robusta ankole coffee producers coop Uganda
16 Robusta andrew hetzel India
17 Robusta andrew hetzel India
18 Robusta kawacom uganda ltd Uganda
19 Robusta nitubaasa ltd Uganda
20 Robusta mannya coffee project Uganda
21 Robusta andrew hetzel India
22 Robusta andrew hetzel India
23 Robusta andrew hetzel United States
24 Robusta luis robles Ecuador
25 Robusta luis robles Ecuador
26 Robusta james moore United States
27 Robusta cafe politico India
28 Robusta cafe politico Vietnam
Farm.Name Lot.Number
1 kyangundu cooperative society NaN \
2 sethuraman estate kaapi royale 25
3 sethuraman estate NaN
4 ugacof project area NaN
5 katikamu capca farmers association NaN
6 NaN NaN
7 sethuraman estates NaN
8 sethuraman estate kaapi royale 7
9 sethuraman estate RKR
10 ishaka NaN
11 ugacof project area NaN
12 sethuraman estate kaapi royale RC AB
13 sethuraman estates NaN
14 kasozi coffee farmers NaN
15 kyangundu coop society NaN
16 sethuraman estate NaN
17 sethuraman estates NaN
18 bushenyi NaN
19 kigezi coffee farmers association NaN
20 mannya coffee project NaN
21 sethuraman estates NaN
22 sethuraman estates NaN
23 sethuraman estates NaN
24 robustasa Lavado 1
25 robustasa Lavado 3
26 fazenda cazengo NaN
27 NaN NaN
28 NaN NaN
Mill ICO.Number
1 ankole coffee producers 0 \
2 sethuraman estate 14/1148/2017/21
3 NaN 0000
4 ugacof 0
5 katuka development trust 0
6 (self) NaN
7 NaN NaN
8 sethuraman estate 14/1148/2017/18
9 sethuraman estate 14/1148/2016/17
10 nsubuga umar 0
11 ugacof 0
12 sethuraman estate 14/1148/2016/12
13 NaN NaN
14 NaN 0
15 ankole coffee producers coop union ltd 0
16 NaN 0000
17 sethuraman estates NaN
18 kawacom 0
19 nitubaasa 0
20 mannya coffee project 0
21 NaN NaN
22 sethuraman estates NaN
23 sethuraman estates NaN
24 our own lab NaN
25 own laboratory NaN
26 cafe cazengo NaN
27 NaN 14-1118-2014-0087
28 NaN NaN
Company Altitude
1 ankole coffee producers coop 1488 \
2 kaapi royale 3170
3 sethuraman estate 1000m
4 ugacof ltd 1212
5 katuka development trust ltd 1200-1300
6 cafemakers, llc 3000'
7 cafemakers 750m
8 kaapi royale 3140
9 kaapi royale 1000
10 ugacof ltd 900-1300
11 ugacof ltd 1095
12 kaapi royale 1000
13 cafemakers 750m
14 kasozi coffee farmers association 1367
15 ankole coffee producers coop 1488
16 sethuraman estate 1000m
17 cafemakers, llc 750m
18 kawacom uganda ltd 1600
19 nitubaasa ltd 1745
20 mannya coffee project 1200
21 cafemakers 750m
22 cafemakers, llc 750m
23 cafemakers, llc 3000'
24 robustasa NaN
25 robustasa 40
26 global opportunity fund 795 meters
27 cafe politico NaN
28 cafe politico NaN
Region ... Color Category.Two.Defects
1 sheema south western ... Green 2 \
2 chikmagalur karnataka indua ... NaN 2
3 chikmagalur ... Green 0
4 central ... Green 7
5 luwero central region ... Green 3
6 chikmagalur ... Green 0
7 chikmagalur ... Green 0
8 chikmagalur karnataka india ... Bluish-Green 0
9 chikmagalur karnataka ... Green 0
10 western ... Green 6
11 iganga namadrope eastern ... Green 1
12 chikmagalur karnataka ... Green 0
13 chikmagalur ... Green 1
14 eastern ... Green 7
15 south western ... Green 2
16 chikmagalur ... Green 0
17 chikmagalur ... Blue-Green 0
18 western ... Green 1
19 western ... Green 2
20 southern ... Green 1
21 chikmagalur ... Bluish-Green 1
22 chikmagalur ... Green 0
23 chikmagalur ... Green 0
24 san juan, playas ... Blue-Green 1
25 san juan, playas ... Blue-Green 0
26 kwanza norte province, angola ... NaN 6
27 NaN ... Green 1
28 NaN ... NaN 9
Expiration Certification.Body
1 June 26th, 2015 Uganda Coffee Development Authority \
2 October 31st, 2018 Specialty Coffee Association
3 April 29th, 2016 Specialty Coffee Association
4 July 14th, 2015 Uganda Coffee Development Authority
5 June 26th, 2015 Uganda Coffee Development Authority
6 February 28th, 2013 Specialty Coffee Association
7 May 15th, 2015 Specialty Coffee Association
8 October 25th, 2018 Specialty Coffee Association
9 August 17th, 2017 Specialty Coffee Association
10 August 5th, 2015 Uganda Coffee Development Authority
11 June 26th, 2015 Uganda Coffee Development Authority
12 August 23rd, 2017 Specialty Coffee Association
13 May 19th, 2015 Specialty Coffee Association
14 July 14th, 2015 Uganda Coffee Development Authority
15 July 14th, 2015 Uganda Coffee Development Authority
16 April 29th, 2016 Specialty Coffee Association
17 June 3rd, 2014 Specialty Coffee Association
18 June 27th, 2015 Uganda Coffee Development Authority
19 June 27th, 2015 Uganda Coffee Development Authority
20 June 27th, 2015 Uganda Coffee Development Authority
21 May 19th, 2015 Specialty Coffee Association
22 June 20th, 2014 Specialty Coffee Association
23 February 28th, 2013 Specialty Coffee Association
24 January 18th, 2017 Specialty Coffee Association
25 January 18th, 2017 Specialty Coffee Association
26 December 23rd, 2015 Specialty Coffee Association
27 August 25th, 2015 Specialty Coffee Association
28 August 25th, 2015 Specialty Coffee Association
Certification.Address
1 e36d0270932c3b657e96b7b0278dfd85dc0fe743 \
2 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
3 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
4 e36d0270932c3b657e96b7b0278dfd85dc0fe743
5 e36d0270932c3b657e96b7b0278dfd85dc0fe743
6 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
7 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
8 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
9 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
10 e36d0270932c3b657e96b7b0278dfd85dc0fe743
11 e36d0270932c3b657e96b7b0278dfd85dc0fe743
12 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
13 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
14 e36d0270932c3b657e96b7b0278dfd85dc0fe743
15 e36d0270932c3b657e96b7b0278dfd85dc0fe743
16 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
17 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
18 e36d0270932c3b657e96b7b0278dfd85dc0fe743
19 e36d0270932c3b657e96b7b0278dfd85dc0fe743
20 e36d0270932c3b657e96b7b0278dfd85dc0fe743
21 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
22 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
23 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
24 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
25 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
26 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
27 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
28 ff7c18ad303d4b603ac3f8cff7e611ffc735e720
Certification.Contact unit_of_measurement
1 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m \
2 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
3 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
4 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m
5 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m
6 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
7 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
8 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
9 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
10 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m
11 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m
12 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
13 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
14 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m
15 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m
16 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
17 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
18 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m
19 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m
20 03077a1c6bac60e6f514691634a7f6eb5c85aae8 m
21 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
22 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
23 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
24 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
25 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
26 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
27 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
28 352d0cf7f3e9be14dad7df644ad65efc27605ae2 m
altitude_low_meters altitude_high_meters altitude_mean_meters
1 1488.0 1488.0 1488.0
2 3170.0 3170.0 3170.0
3 1000.0 1000.0 1000.0
4 1212.0 1212.0 1212.0
5 1200.0 1300.0 1250.0
6 3000.0 3000.0 3000.0
7 750.0 750.0 750.0
8 3140.0 3140.0 3140.0
9 1000.0 1000.0 1000.0
10 900.0 1300.0 1100.0
11 1095.0 1095.0 1095.0
12 1000.0 1000.0 1000.0
13 750.0 750.0 750.0
14 1367.0 1367.0 1367.0
15 1488.0 1488.0 1488.0
16 1000.0 1000.0 1000.0
17 750.0 750.0 750.0
18 1600.0 1600.0 1600.0
19 1745.0 1745.0 1745.0
20 1200.0 1200.0 1200.0
21 750.0 750.0 750.0
22 750.0 750.0 750.0
23 3000.0 3000.0 3000.0
24 NaN NaN NaN
25 40.0 40.0 40.0
26 795.0 795.0 795.0
27 NaN NaN NaN
28 NaN NaN NaN
[28 rows x 43 columns]>
coffee_df.head(2)
Species | Owner | Country.of.Origin | Farm.Name | Lot.Number | Mill | ICO.Number | Company | Altitude | Region | ... | Color | Category.Two.Defects | Expiration | Certification.Body | Certification.Address | Certification.Contact | unit_of_measurement | altitude_low_meters | altitude_high_meters | altitude_mean_meters | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | Robusta | ankole coffee producers coop | Uganda | kyangundu cooperative society | NaN | ankole coffee producers | 0 | ankole coffee producers coop | 1488 | sheema south western | ... | Green | 2 | June 26th, 2015 | Uganda Coffee Development Authority | e36d0270932c3b657e96b7b0278dfd85dc0fe743 | 03077a1c6bac60e6f514691634a7f6eb5c85aae8 | m | 1488.0 | 1488.0 | 1488.0 |
2 | Robusta | nishant gurjer | India | sethuraman estate kaapi royale | 25 | sethuraman estate | 14/1148/2017/21 | kaapi royale | 3170 | chikmagalur karnataka indua | ... | NaN | 2 | October 31st, 2018 | Specialty Coffee Association | ff7c18ad303d4b603ac3f8cff7e611ffc735e720 | 352d0cf7f3e9be14dad7df644ad65efc27605ae2 | m | 3170.0 | 3170.0 | 3170.0 |
2 rows × 43 columns
coffee_df.tail()
Species | Owner | Country.of.Origin | Farm.Name | Lot.Number | Mill | ICO.Number | Company | Altitude | Region | ... | Color | Category.Two.Defects | Expiration | Certification.Body | Certification.Address | Certification.Contact | unit_of_measurement | altitude_low_meters | altitude_high_meters | altitude_mean_meters | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
24 | Robusta | luis robles | Ecuador | robustasa | Lavado 1 | our own lab | NaN | robustasa | NaN | san juan, playas | ... | Blue-Green | 1 | January 18th, 2017 | Specialty Coffee Association | ff7c18ad303d4b603ac3f8cff7e611ffc735e720 | 352d0cf7f3e9be14dad7df644ad65efc27605ae2 | m | NaN | NaN | NaN |
25 | Robusta | luis robles | Ecuador | robustasa | Lavado 3 | own laboratory | NaN | robustasa | 40 | san juan, playas | ... | Blue-Green | 0 | January 18th, 2017 | Specialty Coffee Association | ff7c18ad303d4b603ac3f8cff7e611ffc735e720 | 352d0cf7f3e9be14dad7df644ad65efc27605ae2 | m | 40.0 | 40.0 | 40.0 |
26 | Robusta | james moore | United States | fazenda cazengo | NaN | cafe cazengo | NaN | global opportunity fund | 795 meters | kwanza norte province, angola | ... | NaN | 6 | December 23rd, 2015 | Specialty Coffee Association | ff7c18ad303d4b603ac3f8cff7e611ffc735e720 | 352d0cf7f3e9be14dad7df644ad65efc27605ae2 | m | 795.0 | 795.0 | 795.0 |
27 | Robusta | cafe politico | India | NaN | NaN | NaN | 14-1118-2014-0087 | cafe politico | NaN | NaN | ... | Green | 1 | August 25th, 2015 | Specialty Coffee Association | ff7c18ad303d4b603ac3f8cff7e611ffc735e720 | 352d0cf7f3e9be14dad7df644ad65efc27605ae2 | m | NaN | NaN | NaN |
28 | Robusta | cafe politico | Vietnam | NaN | NaN | NaN | NaN | cafe politico | NaN | NaN | ... | NaN | 9 | August 25th, 2015 | Specialty Coffee Association | ff7c18ad303d4b603ac3f8cff7e611ffc735e720 | 352d0cf7f3e9be14dad7df644ad65efc27605ae2 | m | NaN | NaN | NaN |
5 rows × 43 columns
coffee_df.info()
<class 'pandas.core.frame.DataFrame'>
Index: 28 entries, 1 to 28
Data columns (total 43 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Species 28 non-null object
1 Owner 28 non-null object
2 Country.of.Origin 28 non-null object
3 Farm.Name 25 non-null object
4 Lot.Number 6 non-null object
5 Mill 20 non-null object
6 ICO.Number 17 non-null object
7 Company 28 non-null object
8 Altitude 25 non-null object
9 Region 26 non-null object
10 Producer 26 non-null object
11 Number.of.Bags 28 non-null int64
12 Bag.Weight 28 non-null object
13 In.Country.Partner 28 non-null object
14 Harvest.Year 28 non-null int64
15 Grading.Date 28 non-null object
16 Owner.1 28 non-null object
17 Variety 3 non-null object
18 Processing.Method 10 non-null object
19 Fragrance...Aroma 28 non-null float64
20 Flavor 28 non-null float64
21 Aftertaste 28 non-null float64
22 Salt...Acid 28 non-null float64
23 Bitter...Sweet 28 non-null float64
24 Mouthfeel 28 non-null float64
25 Uniform.Cup 28 non-null float64
26 Clean.Cup 28 non-null float64
27 Balance 28 non-null float64
28 Cupper.Points 28 non-null float64
29 Total.Cup.Points 28 non-null float64
30 Moisture 28 non-null float64
31 Category.One.Defects 28 non-null int64
32 Quakers 28 non-null int64
33 Color 25 non-null object
34 Category.Two.Defects 28 non-null int64
35 Expiration 28 non-null object
36 Certification.Body 28 non-null object
37 Certification.Address 28 non-null object
38 Certification.Contact 28 non-null object
39 unit_of_measurement 28 non-null object
40 altitude_low_meters 25 non-null float64
41 altitude_high_meters 25 non-null float64
42 altitude_mean_meters 25 non-null float64
dtypes: float64(15), int64(5), object(23)
memory usage: 9.6+ KB
coffee_df.columns[42]
'altitude_mean_meters'
col_types = coffee_df.dtypes
col_types[:5]
Species object
Owner object
Country.of.Origin object
Farm.Name object
Lot.Number object
dtype: object
type(col_types[0])
numpy.dtype[object_]
for col_name in coffee_df.columns:
print(col_name[:3])
Spe
Own
Cou
Far
Lot
Mil
ICO
Com
Alt
Reg
Pro
Num
Bag
In.
Har
Gra
Own
Var
Pro
Fra
Fla
Aft
Sal
Bit
Mou
Uni
Cle
Bal
Cup
Tot
Moi
Cat
Qua
Col
Cat
Exp
Cer
Cer
Cer
uni
alt
alt
alt
my_list = ['honda','ford','nissan']
type(my_list)
list
my_list[-1]
'nissan'
short_names = [col_name[:3] for col_name in coffee_df.columns]
type(short_names)
list
short_names
['Spe',
'Own',
'Cou',
'Far',
'Lot',
'Mil',
'ICO',
'Com',
'Alt',
'Reg',
'Pro',
'Num',
'Bag',
'In.',
'Har',
'Gra',
'Own',
'Var',
'Pro',
'Fra',
'Fla',
'Aft',
'Sal',
'Bit',
'Mou',
'Uni',
'Cle',
'Bal',
'Cup',
'Tot',
'Moi',
'Cat',
'Qua',
'Col',
'Cat',
'Exp',
'Cer',
'Cer',
'Cer',
'uni',
'alt',
'alt',
'alt']
3.3. Questions After Class#
3.3.1. • will we be gathering our own data or will it all be provided for the course?#
3.3.2. Will you always give us an answer key for assignments?#
No, but we will always give personalized feedback.
3.3.3. will we be cleaning data?#
Yes, see the notes from the first class.
3.3.4. Will we do correlations later?#
Yes
3.3.5. will we go over more imports like pandas?#
Yes, we will use other libraries. In A2, you’ll even import your own code.
3.3.6. How will datasets be used in conjunction with one another?#
We will combine data in a few weeks.
3.3.7. How similar of an alternative to modeling in R exists in python?#
They are both compelte languages so at some level, they can both do all the same things. Some libraries are easier/better for specific things in one language or the other.
3.3.8. Will we be working with databases at all in this class?#
A little. We’ll pull from a database into python.
3.3.9. Are we going going to be using pandas a lot in this class?#
Yes. We will use pandas for almost every single remaining class session this semester.
3.3.10. how do you short-cut fill variable names in jupyter#
Press tab to autocomplete
3.3.11. what is the most efficient way to get help on the homework ?#
Accept the assignment and make an issue or go to office hours for general questions. For clarifying questions, you can post an issue on the course website.
If you are stuck with some progress made, upload (or push) your code first and then ask for help so we can see where you are.
3.3.12. is there a best or most common way to organize data for use#
csv
3.3.13. how would you laod a csv file with python if i was using visual studio instead of jupyter?#
All of the code we are writing will work in any python environment that has the libraries. the Editor you use (jupyter vs VSCode vs PyCharm) does not impact what you can do with python. Which interpreter you use can impact and jupyter does default to ipython instead of the core python kernel, but that does not change how to load data.
Remember that jupyter is not on a cloud service. YOu can use any file on your computer with a relative path.