Created
June 13, 2017 04:00
-
-
Save laspluviosillas/b41923c64eb4ea53ef344c8788f97912 to your computer and use it in GitHub Desktop.
Using python comprehension to analyze enron data. (udacity machine learning)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# =========================================== | |
# Output first entry from dict to see values. | |
# =========================================== | |
# print enron_data[enron_data.keys()[0]] | |
# ============================= | |
# Get # of persons of interest | |
# (uses dict comprehension) | |
# ============================ | |
pois = {k: v for k, v in enron_data.iteritems() if enron_data[k]["poi"] } | |
print "PERSONS OF INTEREST: " + str(len(pois)) | |
# ========================== | |
# Get # of defined salaries. | |
# (uses list comprehension) | |
# ========================== | |
defined_salaries = [d['salary'] for d in enron_data.values() if d['salary'] != 'NaN'] | |
print "DEFINED SALARIES: " + str(len(defined_salaries)) | |
# ========================== | |
# Get # of defined emails | |
# (uses list comprehension) | |
# ========================== | |
defined_emails = [d['email_address'] for d in enron_data.values() if d['email_address'] != 'NaN'] | |
print "DEFINED EMAILS: " + str(len(defined_emails)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment