python dataframe pandas drop column using int
dataframe, pandas, python
Solution
You can delete column on `i` index like this:
df.drop(df.columns[i], axis=1)
It could work strange, if you have duplicate names in columns, so to do this you can rename column you want to delete column by new name. Or you can reassign DataFrame like this:
df = df.iloc[:, [j for j, c in enumerate(df.columns) if j != i]]
Problem
I understand that to drop a column you use df.drop('column name', axis=1). Is there a way to drop a column using a numerical index instead of the column name?