How to drop pandas consecutive column by column name simultaneously?

Nabih Bawazir :

Here's my data

Id   Column1  Column2  Column3  Column4 ....  Column112  Column113 ... Column143
1         67       89       86       43              56         72            67

The Output I expected,

Id   Column1  Column113 ... Column143
1         67         72            67

What I did

df.drop(['Column2', 'Column3', ... ,'Column112'], axis = 1)

But this is not efficient, how to do this effectively?

jezrael :

Use:

df1 = df.drop(df.loc[:, 'Column2':'Column112'].columns, axis=1)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=21280&siteId=1