python - Match Exactly column name in a data frame -


i have following

for col in features:      my_features = pd.merge(my_features,drug.ix[:,[col]], left_index = true,right_index=true) 

which produces following

my_features.columns out[373]: index([u'**pcbd1_x**', u'**pcbd1_y**', u'klk8', u'tnfsf13 /// tnfsf12-', u'ripk5', u'svil'], dtype='object') 

while should match features

features out[375]: ['pcbd1', 'klk8', 'tnfsf13 /// tnfsf12-', 'ripk5', 'svil'] 

how can change "col" match when creating data frame above .in other words avoid bold column matches. regular expression problem.

update

i trying extract columns listed in "features" "drug". before

for col in features:  my_features = pd.merge(my_features,drug.ix[:,[col]], left_index = true,right_index=true)enter code here 

i have following line create structure my_features

my_features =  pd.dataframe( drug.ix[:,features[0]] , index = drug.index , columns=[features[0]]) 

so whole code like

my_features =  pd.dataframe( drug.ix[:,features[0]] , index = drug.index , columns=[features[0]]) iterfeatures = iter(features) next(iterfeatures) col in features:     my_features = pd.merge(my_features,drug.ix[:,[col]], left_index = true,right_index=true) 

you can use pandas.dataframe.filter(). has regex argument [as "like" argument]. http://pandas.pydata.org/pandas-docs/stable/generated/pandas.dataframe.filter.html


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -