List all columns in a dataframe containing a string
Post date: Jan 13, 2015 5:23:18 AM
For example, I want to list all the columns containing string "ITEM", so here is the list:
[col for col in df.columns if 'ITEM' in col]
And if I want to slice on those columns, I will do this:
df[[col for col in df.columns if 'ITEM' in col]]
and the output dataframe would contain the following columns:
ITEM_QUANTITY
ITEM_CONDITION_TYPE
ITEM