Skip to content

Instantly share code, notes, and snippets.

Last active March 26, 2019 18:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Example with Apply
import numpy as np
import pandas as pd
from datetime import date
def extract_procedure_features(physician_procedures):
one_hot_procedures = pd.get_dummies(physician_procedures.procedure_code, prefix='procedure')
dummied_procedures = pd.concat([physician_procedures.number_of_patients, one_hot_procedures], axis=1)
def numerize(row):
return np.asarray(row.number_of_patients) * np.asarray(row)
numerized_procedures = dummied_procedures.apply(numerize, axis=1)\
.drop('number_of_patients', axis=1)
combined_numerized_procedures = numerized_procedures.assign(physician_id=physician_procedures.physician_id)\
return combined_numerized_procedures
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment