How to delete columns from a Pandas DataFrame by index in Python

Columns from a Pandas DataFrame can be deleted by their index in the DataFrame rather than by their column name. This can be useful if the columns in a DataFrame are unnamed or if there is more than one column with the same name.

Solution for How to delete columns from a Pandas DataFrame by index in Python : You can use pd.DataFrame.drop() to delete columns from a Pandas DataFrame by index Call pd.DataFrame.drop(labels=None, axis=1, inplace=True) with labels set to pd.DataFrame.columns[x] where x is the column index to be deleted.


how-to-delete-columns-from-a-pandas-dataframe-by-index-in-python