Actually, sodium is fairly easily prepared by electrolysis. Commercially, it used to be made by electrolyzing using a mercury-metal negative electrode, which collected the sodium formed in an amalgam. ("amalgam" is the term for an alloy where one component is mercury metal). The mercury is then pumped away, and is then distilled off, leaving the sodium metal behind.
Sodium can also be prepared by electrolying a molten salt, sodium chloride might do, although this would involve very high temperatures to melt the salt.