Issue
I have a data frame that has multiple columns, example:
Prod_A Prod_B Prod_C State Region
1 1 0 1 1 1
I would like to drop all columns that starts with Prod_, (I can't select or drop by name because the data frame has 200 variables) Is it possible to do this ?
Thank you
Solution
Use startswith
for mask and then delete columns with loc
and boolean indexing
:
df = df.loc[:, ~df.columns.str.startswith('Prod')]
print (df)
State Region
1 1 1
Answered By - jezrael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.