I have a large pandas dataframe (>100 columns). I need to drop various sets of columns and i'm hoping there is a way of using the old
df.drop(df.columns['slices'],axis=1)
I've built selections such as:
a = df.columns[3:23]
b = df.colums[-6:]
as a
and b
represent column sets I want to drop.
The following
list(df)[3:23]+list(df)[-6:]
yields the correct selection, but i can't implement it with a drop
:
df.drop(df.columns[list(df)[3:23]+list(df)[-6:]],axis=1)
ValueError: operands could not be broadcast together with shapes (20,) (6,)
I looked around but can't get my answer.
Selecting last n columns and excluding last n columns in dataframe
(Below pertains to the error I receive):
python numpy ValueError: operands could not be broadcast together with shapes
This one feels like they're having a similar issue, but the 'slices' aren't separate: Deleting multiple columns based on column names in Pandas
Cheers