Data Cleaning

File format issues

Quoting was messed up in the CSV for ridings 24047, 35003, 35084, 59029 in election 40. Fixed them up by hand.

Dual-Candidate elections

Some ridings elected two members. Wikipedia says:

While electoral districts at both the federal and provincial levels are now exclusively single-member districts, multiple-member districts have been used in the past. The federal riding of Ottawa elected two members from 1872 to 1933. The federal riding of Halifax elected two members from the 1800s to 1966.

These ridings are found in SQL and divided into two ridings, each electing a single member. The original riding name is suffixed with “-1” and “-2”. One winner is assigned to each; similarly for losing candidates.

Cleaning Party Names

The party names in the raw data are not uniform. For example, it contains “N.D.P.”, “NDP-New Democratic Party”, and “New Democratic Party”. It’s safe to say that these all refer to the same party.

As a first step, the following party names were normalized.

),
Normalized NameOriginal Names
Animal Alliance/Environment VotersAnimal Alliance Environment Voters Party of Canada
Animal Alliance/Environment Voters
AAEV Party of Canada
Canadian Action PartyCAP
Canadian Action Party
Canadian Action
Christian Heritage PartyCHP Canada
Christian Heritage Party
Christian Heritage Party of Canada
Communist PartyCommunist
Communist Party of Canada
Green PartyGreen Party
Green Party of Canada
IndependentIndependent
No Affiliation
No affiliation to a recognised party
Libertarian PartyLibertarian
Libertarian Party of Canada
Marijuana PartyMarijuana Party
Radical Marijuana
Marxist-Leninist PartyMarxist-Leninist
Marxist-Leninist Party
ML
Newfoundland and Labrador First PartyNewfoundland and Labrador First Party
NL First Party
New Democratic PartyN.D.P.
NDP-New Democratic Party
New Democratic Party
People's Political Power Party of CanadaPeople's Political Power Party of Canada
PPP
Pirate PartyPirate
Pirate Party
Pirate Party of Canada
Progressive Canadian PartyProgressive Canadian Party
PC Party
Reform PartyReform
Reform Party of Canada
Republican PartyRepublican
Republican Party
Rhinoceros PartyRhinoceros
Parti Rhinocéros
Parti Rhinocéros Party
neorhino.ca
United Reform MovementUnited Reform
United Reform Movement
Western Block PartyWBP
Western Block Party

Secondly, Wikipedia lists a number of parties that went through name changes. Taking those into account gives the following list:

Normalized NameOriginal Names
Animal Alliance/Environment VotersAnimal Alliance Environment Voters Party of Canada
Animal Alliance/Environment Voters
Canadian Action PartyCAP
Canadian Action Party
Canadian Action
Christian Heritage PartyCHP Canada
Christian Heritage Party
Christian Heritage Party of Canada
Co-operative Commonwealth FederationCo-operative Commonwealth Federation
New Party
Communist PartyCommunist
Communist Party of Canada
United Progressive
Unity
Labour Progressive Party
Green PartyGreen Party
Green Party of Canada
IndependentIndependent
No Affiliation
No affiliation to a recognised party
LabourLabour
Conservative-Labour
Farmer Labour
Farmer-United Labour
Labour Farmer
Liberal Labour
Liberal Labour Party
National Labour
United Farmers of Ontario-Labour
United Farmers-Labour
Liberal Labour ProgressiveLiberal Labour Progressive
National Liberal Progressive
Libertarian PartyLibertarian
Libertarian Party of Canada
Marijuana PartyMarijuana Party
Radical Marijuana
Marxist-Leninist PartyMarxist-Leninist
Marxist-Leninist Party
ML
New Democratic PartyN.D.P.
NDP-New Democratic Party
New Democratic Party
Pirate PartyPirate
Pirate Party
Pirate Party of Canada
Progressive Canadian PartyProgressive Canadian Party
PC Party
Progressive Conservative PartyProgressive Conservative Party
Liberal-Conservative
National Liberal and Conservative Party
National Government
Reform PartyReform
Reform Party of Canada
Republican PartyRepublican
Republican Party
Rhinoceros PartyRhinoceros
Parti Rhinocéros
Parti Rhinocéros Party
neorhino.ca
Social Credit PartySocial Credit Party of Canada
New Democracy
Ralliement Créditiste
Candidats des électeurs
United FarmersUnited Farmers
United Farmers of Alberta
United Farmers of Ontario
Farmer
United Reform MovementUnited Reform
United Reform Movement
Western Block PartyWBP
Western Block Party