You don't "erase" as much as "write over" the data on a hard disk.
Your write head "writes" spots on the platter such that some spots are magnetized as though the spot were a magnet with the "south" end up, and other spots were "north" end up.
To "erase," you write zeroes (or ones) to all the addressable spots on the platter. This doesn't actually set all the spots to the same direction. The data you write are encoded in various ways. All zeroes would probably result in a series of alternating "north up" and "south up" spots.
The whole thing is much more complicated than that, but is based on the ability of the write head to change the magnetic polarity of small spots on the platter.
The write head is an electromagnetic that can make very small (but strong) magnetic fields. Push current through one way and it forces a spot on the platter to magnetize "north up." Push current through the write head the other way and it forces a spot on the platter to magnetize "south up." Changing the eletrical polarity of the current through the write head changes the magnetic polarity of the written spot on the platter.
The Wikipedia page on the technology of hard disks explains it fairly well. That link goes right to the section on how magnetic recording is done on hard disk drives.
This image from the Wikipedia page shows how data is written:
Longitudal recording changes which direction is north or south (with or against the rotation direction.)
Perpendicular recording changes whether up or down is north or south - that's the one I used in the explanation above.
As Marcus Müller says, you really almost never erase data from a hard disk.
When you delete a file, all that happens is that the operating system writes a marker in the file system that says "this file no longer needed, its space can be used for something else." The operating system then ignores that file when showing you the list of files on your disk.
There are programs that look for such flagged files and allow you to recover them. If the space the file occupies hasn't been taken for a new file, then you can often recover a deleted file just by removing the "deleted" marker.
You can really delete files or the entire contents of disk, if you need to.
There are programs you can use that will overwrite all the storage space of a file with ones or zeroes, or random data, and then mark them as deleted. You can still "recover" the file, but the data is gone because you overwrote it with garbage.
SDelete from the Microsoft SysInternals is an example of a program that overwrites files to really remove the data.
There are programs that do the same thing to whole disks. They overwrite all data bits with ones or zeroes or random data. That takes a long time on a modern hard disk because they are so large.
Many flash based SSDs can do pretty much the same thing in an instant. They encrypt the data before writing it using an internal key. To delete, you just ask the disk to generate a new key. The old key is gone, the new key can't decrypt the old data - everything "deleted" in a flash. :)