Skip to content

Instantly share code, notes, and snippets.

@jacobod
Created March 15, 2018 04:09
Show Gist options
  • Save jacobod/7b8c15bf7a4d52889da39fa31e795632 to your computer and use it in GitHub Desktop.
Save jacobod/7b8c15bf7a4d52889da39fa31e795632 to your computer and use it in GitHub Desktop.
# creating copy
my_dataset = data_dict
# creating new features
for key in my_dataset:
empl = my_dataset[key]
perc_to_poi, perc_from_poi = [] , []
if (empl['from_this_person_to_poi'] != 'NaN') & (empl['from_messages'] != 'NaN'):
perc_to_poi = float(empl['from_this_person_to_poi'])/float(empl['from_messages'])
empl['perc_to_poi'] = perc_to_poi
else:
empl['perc_to_poi'] = 0
if (empl['from_poi_to_this_person'] != 'NaN') & (empl['to_messages'] != 'NaN'):
perc_to_poi = float(empl['from_poi_to_this_person'])/float(empl['to_messages'])
empl['perc_from_poi'] = perc_to_poi
else:
empl['perc_from_poi'] = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment