Skip to content

Latest commit

 

History

History
135 lines (93 loc) · 5.96 KB

05b-python_advanced.md

File metadata and controls

135 lines (93 loc) · 5.96 KB

Advanced Python

###Regular Expressions, Dictionary, Writing to CSV File

This question has multiple parts, and will take 20+ hours to complete, depending on your python proficiency level. Knowing these skills will be extremely beneficial during the first few weeks of the bootcamp.

For Part 1, use of regular expressions is optional. Work can be completed using a programming approach of your preference.


The data file represents the Biostats Faculty List at University of Pennsylvania

This data is available in this file: faculty.csv


###Part I - Regular Expressions

####Q1. Find how many different degrees there are, and their frequencies: Ex: PhD, ScD, MD, MPH, BSEd, MS, JD, etc.

There are 6 ScD's, 1 JD, 1 MD, 1 BSEd, 2 MPH's, 31 PhD's, 2 MS's, and 1 MA.

####Q2. Find how many different titles there are, and their frequencies: Ex: Assistant Professor, Professor

There are 13 "Professors of Biostatistics," 12 "Associate Professors of Biostatistics" and 12 "Assistant Professors of Biostatistics."

####Q3. Search for email addresses and put them in a list. Print the list of email addresses.

['bellamys@mail.med.upenn.edu', 'warren@upenn.edu', 'bryanma@upenn.edu', 'jinboche@upenn.edu', 'sellenbe@upenn.edu', 'jellenbe@mail.med.upenn.edu', 'ruifeng@upenn.edu', 'bcfrench@mail.med.upenn.edu', 'pgimotty@upenn.edu', 'wguo@mail.med.upenn.edu', 'hsu9@mail.med.upenn.edu', 'rhubb@mail.med.upenn.edu', 'whwang@mail.med.upenn.edu', 'mjoffe@mail.med.upenn.edu', 'jrlandis@mail.med.upenn.edu', 'liy3@email.chop.edu', 'mingyao@mail.med.upenn.edu', 'hongzhe@upenn.edu', 'rlocalio@upenn.edu', 'nanditam@mail.med.upenn.edu', 'knashawn@mail.med.upenn.edu', 'propert@mail.med.upenn.edu', 'mputt@mail.med.upenn.edu', 'sratclif@upenn.edu', 'michross@upenn.edu', 'jaroy@mail.med.upenn.edu', 'msammel@cceb.med.upenn.edu', 'shawp@upenn.edu', 'rshi@mail.med.upenn.edu', 'hshou@mail.med.upenn.edu', 'jshults@mail.med.upenn.edu', 'alisaste@mail.med.upenn.edu', 'atroxel@mail.med.upenn.edu', 'rxiao@mail.med.upenn.edu', 'sxie@mail.med.upenn.edu', 'dxie@upenn.edu', 'weiyang@mail.med.upenn.edu']

####Q4. Find how many different email domains there are (Ex: mail.med.upenn.edu, upenn.edu, email.chop.edu, etc.). Print the list of unique email domains.

There are 12 "upenn.edu" domains, 1 "email.chop.edu" domain, 23 "mail.med.upenn.edu" domains, and 1 "cceb.med.upenn.edu" domain.

Place your code in this file: advanced_python_regex.py


###Part II - Write to CSV File

####Q5. Write email addresses from Part I to csv file

Place your code in this file: advanced_python_csv.py

The emails.csv file you create should be added and committed to your forked repository.

Your file, emails.csv, will look like this:

bellamys@mail.med.upenn.edu
warren@upenn.edu
bryanma@upenn.edu

Part III - Dictionary

####Q6. Create a dictionary in the below format:

faculty_dict = { 'Ellenberg': [\
              ['Ph.D.', 'Professor', 'sellenbe@upenn.edu'],\
              ['Ph.D.', 'Professor', 'jellenbe@mail.med.upenn.edu']
                            ],
              'Li': [\
              ['Ph.D.', 'Assistant Professor', 'liy3@email.chop.edu'],\
              ['Ph.D.', 'Associate Professor', 'mingyao@mail.med.upenn.edu'],\
              ['Ph.D.', 'Professor', 'hongzhe@upenn.edu']
                            ]
            }

Print the first 3 key and value pairs of the dictionary:

faculty_dict = { 'Yang': [ [' Ph.D.', 'Assistant Professor of Biostatistics', 'weiyang@mail.med.upenn.edu'] ], 'French': [ [' PhD', 'Associate Professor of Biostatistics', 'bcfrench@mail.med.upenn.edu'] ], 'Stephens': [ [' Ph.D.', 'Assistant Professor of Biostatistics', 'alisaste@mail.med.upenn.edu'] ], ... }

####Q7. The previous dictionary does not have the best design for keys. Create a new dictionary with keys as:

professor_dict = {('Susan', 'Ellenberg'): ['Ph.D.', 'Professor', 'sellenbe@upenn.edu'],\
                ('Jonas', 'Ellenberg'): ['Ph.D.', 'Professor', 'jellenbe@mail.med.upenn.edu'],\
                ('Yimei', 'Li'): ['Ph.D.', 'Assistant Professor', 'liy3@email.chop.edu'],\
                ('Mingyao','Li'): ['Ph.D.', 'Associate Professor', 'mingyao@mail.med.upenn.edu'],\
                ('Hongzhe','Li'): ['Ph.D.', 'Professor', 'hongzhe@upenn.edu']
            }

Print the first 3 key and value pairs of the dictionary:

faculty_dict = { ('Phyllis', 'Gimotty'): [' Ph.D', 'Professor of Biostatistics', 'pgimotty@upenn.edu'], ('Susan', 'Ellenberg'): [' Ph.D.', 'Professor of Biostatistics', 'sellenbe@upenn.edu'], ('Yimei', 'Li'): [' Ph.D.', 'Assistant Professor of Biostatistics', ... }

####Q8. It looks like the current dictionary is printing by first name. Sort by last name and print the first 3 key and value pairs.

OrderedDict( [ ( ('Bellamy', 'Scarlett'), [' Sc.D.', 'Associate Professor of Biostatistics', 'bellamys@mail.med.upenn.edu'] ), ( ('Bilker', 'Warren'), ['Ph.D.', 'Professor of Biostatistics', 'warren@upenn.edu'] ), ( ('Bryan', 'Matthew'), [' PhD', 'Assistant Professor of Biostatistics', 'bryanma@upenn.edu'] ), ... ]

Place your code in this file: advanced_python_dict.py


If you're all done and looking for an extra challenge, then try the below problem:

Markov (Optional)