Understand how to simulate a statistics
The simulation aims at quantifying the uncertainty of the poll. Candidate A wins win with 51% of the votes. How likely is this?

The code simulates this poll (1000 times as you see in the range function) so that we get the probability of A winning the poll. You can calculate it with e.g.
dist.loc[dist.A&gt;dist.B]['A'].count()/len(dist). You'll find here that A wins with a confidence of ~ 73%. With this you can answer questions like "How big should the size of polled population ($n$) be to get a confidence of 95%?"