python - Optimizing dataframe manipulation: new column based on conditional logic and multiple columns -
currently, works: df['new'] = df.apply( \ lambda x: address[int(x['c1'][:5], 2)]+'_'+str(int(x['c1'][6:11], 2)) \ if x['c1'][5] == '1' \ else address[int(x['c2'][:5], 2)]+'_'+str(int(x['c2'][6:11], 2)), axis=1) ` address dictionary. but it's really slow . specifically, apply ing whole dataframe considerably slower apply ing selected column. however, new column based on multiple columns , i'm not sure how implement that. additionally, there way vectorize these types of logical/conditional statements? sample dataframe: <bound method dataframe.head of c1 c2 0 0000100111000111 0010110011000111 1 0001000111000111 0010110011000111 2 0101010001001010 0000000000000000 3 0101010010001110 0000000000000000 4 0101010011101010 0000000000000000 5 0111111100000100 0000000000000000 6 0111110010010110 000000...