Drop multiple columns in pandas

后端 未结 2 1371
悲&欢浪女
悲&欢浪女 2020-12-08 03:35

I am trying to drop multiple columns (column 2 and 70 in my data set, indexed as 1 and 69 respectively) by index number in a pandas data frame with the following code:

相关标签:
2条回答
  • 2020-12-08 04:14

    Try this

    df.drop(df.iloc[:, 1:69], inplace=True, axis=1)

    This works for me

    0 讨论(0)
  • 2020-12-08 04:20

    You don't need to wrap it in a list with [..], just provide the subselection of the columns index:

    df.drop(df.columns[[1, 69]], axis=1, inplace=True)
    

    as the index object is already regarded as list-like.

    0 讨论(0)
提交回复
热议问题