数据= pd.DataFrame({ ‘性别’:[ ‘M’, ‘F’, ‘M’], ‘ICDS’: 'I10'],[ 'I20', 'I30'],[ 'I40' , ‘配有’:1,2,4,5-],[3,4,6],[5,6,7})
哪一个 机 </跨度> 学习 </跨度> 算法应该用于这种类型的数据吗?我想到了
您实际上可以将这些meds添加为功能,如下所示:
data=pd.DataFrame({'gender':['m','f','m'],'icds':[['i10'],['i20','i30'],['i40']],'med':[['xanex','isotopin'],['cz3','hicet','t-montair'],['t-montair','xanex']]}) all_med= list(np.unique(flatten(list(data['med'].values)))) for meds in all_med: med_list=[] for i in xrange(len(data)): d= data['med'][i] if meds in d: med_list.append(1) else: med_list.append(0) data[meds]=med_list
输出:
gender icds med cz3 hicet isotopin \ 0 m [i10] [xanex, isotopin] 0 0 1 1 f [i20, i30] [cz3, hicet, t-montair] 1 1 0 2 m [i40] [t-montair, xanex] 0 0 0 t-montair xanex 0 0 1 1 1 0 2 1 1