1. Help Center
  2. Python Programming

How will you delete indices, rows and columns from a dataframe?

Execute del df.index.name for removing the index by name.
Alternatively, the df.index.name can be assigned to None.
For example, if you have the below dataframe:
Column 1
Names
John 1
Jack 2
Judy 3
Jim 4
To drop the index name “Names”:
df.index.name = None
# Or run the below:
# del df.index.name
print(df)
Column 1
John 1
Jack 2
Judy 3
Jim 4
To delete row/column from dataframe:
 
drop() method is used to delete row/column from dataframe.
The axis argument is passed to the drop method where if the value is 0, it indicates to drop/delete a row and if 1 it has to drop the column.
Additionally, we can try to delete the rows/columns in place by setting the value of inplace to True. This makes sure that the job is done without the need for reassignment.
The duplicate values from the row/column can be deleted by using the drop_duplicates() method.