Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Working with Excel Files
Summary

Instruction

Well done!

Sometimes we want to remove a sheet that is no longer useful. We can do so in two ways. The first way is to use the remove() method:

wb.remove(wb["worksheet_name"])

The other way is to use the del keyword, accessing the appropriate worksheet with square brackets:

del wb["worksheet_name"]

Either way, this action results in deleting a given worksheet and all of its contents, so proceed with caution. Otherwise, you may lose some precious data.

However, remember that you have to save changes to a file. If you delete a worksheet from your workbook in Python, it doesn't mean it will be deleted from the xlsx file. You must save the workbook to a file if you want to preserve your changes.

Exercise

Remove the Housing worksheet; we won't be needing it. You can access the existing workbook using the wb variable.

Save the modified workbook in the file budget.xlsx.