Last active
March 26, 2019 18:59
-
-
Save chelseatroy/52486cab46f0109ca78df73a357f911e to your computer and use it in GitHub Desktop.
Example with Apply
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
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)\ | |
.groupby('physician_id')\ | |
.sum()\ | |
.reset_index() | |
combined_numerized_procedures.to_csv('path/to/data.csv') | |
return combined_numerized_procedures |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment