Skip to content

Instantly share code, notes, and snippets.

@laspluviosillas
Created June 13, 2017 04:00
Show Gist options
  • Save laspluviosillas/b41923c64eb4ea53ef344c8788f97912 to your computer and use it in GitHub Desktop.
Save laspluviosillas/b41923c64eb4ea53ef344c8788f97912 to your computer and use it in GitHub Desktop.
Using python comprehension to analyze enron data. (udacity machine learning)
# ===========================================
# 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