Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Find column whose name contains a specific string

df.loc[:,df.columns.str.contains("spike")]
#OR
spike_cols =[x for x in df.columns[df.columns.str.contains('spike')]]
#OR
spike_cols = [x for x in df.columns if 'spike' in x]
df[spike_cols]
#To drop spike_cols
df[df.columns.drop(spike_cols)]
#OR
# select columns containing 'spike'
df.filter(like='spike', axis=1)
#OR
df2 = df.filter(regex='spike')


Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #Find #column #specific #string
ADD COMMENT
Topic
Name
7+3 =