Karnataka election results 2013

Unfortunately http://eci.nic.in/ does not provide the Karnataka 2013 assembly results as a CSV file yet (as of 18 Aug 2013). But numb_and_number posted a scraper and its results, which we'll use.

(This sort of stuff is also available on datameet)

I've converted this into a CSV file called karnataka-2013-results.csv

In [4]:
import pandas as pd
data = pd.read_csv('karnataka-2013-results.csv')
data.head()
Out[4]:
District Candidate Party Votes
0 Afzalpur MALIKAYYA VENKAYYA GUTTEDAR Indian National Congress 38093
1 Afzalpur M.Y.PATIL Karnataka Jantha Paksha 32855
2 Afzalpur VITTHAL HEROOR Janata Dal (Secular) 22847
3 Afzalpur GOVIND VISHWANATH BHAT Samajwadi Party 14648
4 Afzalpur DILIP R. PATIL Bharatiya Janata Party 10347

Before we proceed, let's set some basic options to improve our display.

In [9]:
pd.set_option('display.line_width', 200)
pd.set_option('display.max_columns', 20)

Let's ask some simple questions before we move on to the interesting ones.

How many people voted in Karnataka?

In [36]:
data['Votes'].sum()
Out[36]:
31216708

Who got the maximum votes?

In [39]:
data[data['Votes'] == data['Votes'].max()]
Out[39]:
District Candidate Party Votes Rank
2926 Yeshvanthapura S.T.SOMASHEKAR Indian National Congress 120380 1

In how many places did each party contest?

In [123]:
data['Party'].value_counts()
Out[123]:
Independent                                                   1217
Indian National Congress                                       223
Bharatiya Janata Party                                         222
Janata Dal  (Secular)                                          221
Karnataka Jantha Paksha                                        203
Badavara Shramikara Raitara Congress Party                     175
Bahujan Samaj Party                                            174
Janata Dal  (United)                                           116
Samajwadi Party                                                 27
Nationalist Congress Party                                      24
SOCIAL DEMOCRATIC PARTY OF INDIA                                23
Lok Satta Party                                                 23
National People's Party                                         21
Bharatiya Dr. B.R.Ambedkar Janta Party                          18
Samajwadi Janata Party(Karnataka)                               17
Communist Party of India (Marxist-Leninist) Red Star            17
Communist Party of India  (Marxist)                             16
Lok Jan Shakti Party                                            15
Welfare Party Of India                                          12
Republican Party of India (A)                                   12
Pyramid Party of India                                          11
Hindusthan Nirman Dal                                           11
SOCIALIST UNITY CENTRE OF INDIA (COMMUNIST)                     11
Sarva Janata Party                                              10
Ambedkar National Congress                                      10
Communist Party of India                                         8
Hindustan Janta Party                                            8
Communist Party of India  (Marxist-Leninist)  (Liberation)       8
Rani Chennamma Party                                             8
Karnataka Rajya Ryota Sangha                                     7
Karnataka Makkala Paksha                                         7
Sarvodaya Karnataka Paksha                                       6
Republican Party of India                                        6
Indian Union Muslim League                                       5
All India Anna Dravida Munnetra Kazhagam                         5
Ambedkar Janatha Party                                           5
Bharatiya Praja Paksha                                           5
Bharatiya Janta Dal                                              4
National Development Party                                       3
Kannada Chalavali Vatal Paksha                                   3
Shubha Karnataka                                                 2
Mahila Pradhana Paksha                                           2
Bharatiya Republican Paksha                                      2
Akhila Bharatiya Rytha Party                                     2
Akhil Bharatiya Muslim League (Secular)                          1
Democratic Prajakranthi Party Secularist                         1
Indian National League                                           1
Rashtriya Samaj Paksha                                           1
Bharatiya Peoples Party                                          1
People's Party of India(secular)                                 1
Jai Vijaya Bharathi Party                                        1
Akhil Bharat Hindu Mahasabha                                     1
All India Forward Bloc  (Subhasist)                              1
Vichara Jagruthi Congress Paksha                                 1
Karnataka Swarajya Party                                         1
Socialistic Democratic Party                                     1
Samajwadi Janata Party (Rashtriya)                               1
Shivsena                                                         1
Kamarajar Deseeya Congress                                       1
Length: 59, dtype: int64

Now let's ask interesting questions.

Which party won?

In [51]:
data['Rank'] = data.groupby('District')['Votes'].rank(ascending=False)
data.head()
Out[51]:
District Candidate Party Votes Rank
0 Afzalpur MALIKAYYA VENKAYYA GUTTEDAR Indian National Congress 38093 1
1 Afzalpur M.Y.PATIL Karnataka Jantha Paksha 32855 2
2 Afzalpur VITTHAL HEROOR Janata Dal (Secular) 22847 3
3 Afzalpur GOVIND VISHWANATH BHAT Samajwadi Party 14648 4
4 Afzalpur DILIP R. PATIL Bharatiya Janata Party 10347 5
In [34]:
data[data['Rank'] == 1]['Party'].value_counts()
Out[34]:
Indian National Congress                      121
Bharatiya Janata Party                         40
Janata Dal  (Secular)                          40
Independent                                     9
Karnataka Jantha Paksha                         6
Badavara Shramikara Raitara Congress Party      4
Sarvodaya Karnataka Paksha                      1
Karnataka Makkala Paksha                        1
Samajwadi Party                                 1
dtype: int64

So it's clear that the Congress had a clear sweep. Now, let's ask a few more questions...

Who won by the largest margins?

In [57]:
data[data['Rank'] == 1].set_index('District').head()
Out[57]:
Candidate Party Votes Rank
District
Afzalpur MALIKAYYA VENKAYYA GUTTEDAR Indian National Congress 38093 1
Aland BHOJARAJ RAMCHANDRA Karnataka Jantha Paksha 67085 1
Anekal SHIVANNA B. Indian National Congress 105464 1
Arabhavi BALACHANDRA LAXMANRAO JARKIHOLI Bharatiya Janata Party 99283 1
Arkalgud MANJU A Indian National Congress 61369 1
In [70]:
rank1 = data[data['Rank'] == 1].set_index('District')
rank2 = data[data['Rank'] == 2].set_index('District')
pd.merge(rank1, rank2, left_index=True, right_index=True, suffixes=['1', '2']).head()
Out[70]:
Candidate1 Party1 Votes1 Rank1 Candidate2 Party2 Votes2 Rank2
District
Afzalpur MALIKAYYA VENKAYYA GUTTEDAR Indian National Congress 38093 1 M.Y.PATIL Karnataka Jantha Paksha 32855 2
Aland BHOJARAJ RAMCHANDRA Karnataka Jantha Paksha 67085 1 SUBHASH RUKMAIAH Janata Dal (Secular) 49971 2
Anekal SHIVANNA B. Indian National Congress 105464 1 A. NARAYANASWAMY Bharatiya Janata Party 65282 2
Arabhavi BALACHANDRA LAXMANRAO JARKIHOLI Bharatiya Janata Party 99283 1 UTAGI RAMAPPA KAREPPA Indian National Congress 24062 2
Arkalgud MANJU A Indian National Congress 61369 1 A.T RAMASWAMY Janata Dal (Secular) 52575 2
In [74]:
margins = pd.merge(rank1, rank2, left_index=True, right_index=True, suffixes=['1', '2'])
margins['Margin'] = margins['Votes1'] - margins['Votes2']
In [77]:
margins.sort('Margin', ascending=False).head()
Out[77]:
Candidate1 Party1 Votes1 Rank1 Candidate2 Party2 Votes2 Rank2 Margin
District
Chikkodi-Sadalga PRAKASH BABANNA HUKKERI Indian National Congress 102237 1 BASAVANNI RUDRAPPA SANGAPPAGOL Bharatiya Janata Party 25649 2 76588
Arabhavi BALACHANDRA LAXMANRAO JARKIHOLI Bharatiya Janata Party 99283 1 UTAGI RAMAPPA KAREPPA Indian National Congress 24062 2 75221
Hukkeri UMESH VISHWANATH KATTI Bharatiya Janata Party 81810 1 RAVI BASAVARAJ KARALE Indian National Congress 24484 2 57326
Davanagere North S S MALLIKARJUNA Indian National Congress 88101 1 S A RAVINDRANATH Bharatiya Janata Party 30821 2 57280
B.t.m layout RAMALINGAREDDY Indian National Congress 69712 1 N. SUDHAKAR Bharatiya Janata Party 20664 2 49048

So, despite the Congress having a clean sweep, 2 of the top 5 margin victories are for the BJP. But let's look at percentage of votes.

In [87]:
margins['Votes'] = data.groupby('District')['Votes'].sum()
margins['% Margin'] = margins['Margin'].astype(float) / margins['Votes']
margins.sort('% Margin', ascending=False).head()
Out[87]:
Candidate1 Party1 Votes1 Rank1 Candidate2 Party2 Votes2 Rank2 Margin Votes % Margin
District
Arabhavi BALACHANDRA LAXMANRAO JARKIHOLI Bharatiya Janata Party 99283 1 UTAGI RAMAPPA KAREPPA Indian National Congress 24062 2 75221 145099 0.518412
Chikkodi-Sadalga PRAKASH BABANNA HUKKERI Indian National Congress 102237 1 BASAVANNI RUDRAPPA SANGAPPAGOL Bharatiya Janata Party 25649 2 76588 149375 0.512723
B.t.m layout RAMALINGAREDDY Indian National Congress 69712 1 N. SUDHAKAR Bharatiya Janata Party 20664 2 49048 110486 0.443930
Hukkeri UMESH VISHWANATH KATTI Bharatiya Janata Party 81810 1 RAVI BASAVARAJ KARALE Indian National Congress 24484 2 57326 132961 0.431149
Davanagere North S S MALLIKARJUNA Indian National Congress 88101 1 S A RAVINDRANATH Bharatiya Janata Party 30821 2 57280 134450 0.426032

This effect is even more pronounced now. The same 2 BJP constituencies are also in the top 5 as a percentage, and in fact, BJP's % victory at Arabhavi is the highest in the State.

How many constituencies won by an absolute majority (over 50% votes)? Which parties cornered these?

In [94]:
margins[margins['Votes1'].astype(float) / margins['Votes'] > 0.5].head()
Out[94]:
Candidate1 Party1 Votes1 Rank1 Candidate2 Party2 Votes2 Rank2 Margin Votes % Margin
District
Aland BHOJARAJ RAMCHANDRA Karnataka Jantha Paksha 67085 1 SUBHASH RUKMAIAH Janata Dal (Secular) 49971 2 17114 132385 0.129274
Anekal SHIVANNA B. Indian National Congress 105464 1 A. NARAYANASWAMY Bharatiya Janata Party 65282 2 40182 186461 0.215498
Arabhavi BALACHANDRA LAXMANRAO JARKIHOLI Bharatiya Janata Party 99283 1 UTAGI RAMAPPA KAREPPA Indian National Congress 24062 2 75221 145099 0.518412
Athani LAXMAN SANGAPPA SAVADI Bharatiya Janata Party 74299 1 MAHESH IRANAGOUDA KUMATHALLI Indian National Congress 50528 2 23771 146290 0.162492
B.t.m layout RAMALINGAREDDY Indian National Congress 69712 1 N. SUDHAKAR Bharatiya Janata Party 20664 2 49048 110486 0.443930
In [97]:
margins[margins['Votes1'].astype(float) / margins['Votes'] > 0.5]['Party1'].value_counts()
Out[97]:
Indian National Congress                      40
Janata Dal  (Secular)                          9
Bharatiya Janata Party                         8
Independent                                    4
Badavara Shramikara Raitara Congress Party     3
Karnataka Jantha Paksha                        1
dtype: int64

So Congress has had what looks like a disproportionate share of absolute majorities. Let's confirm that.

In [117]:
majority = pd.DataFrame({
    'Absolute majority': margins[margins['Votes1'].astype(float) / margins['Votes'] > 0.5]['Party1'].value_counts(),
    'Winning party': data[data['Rank'] == 1]['Party'].value_counts(),
})
majority['Ratio'] = majority['Absolute majority'] / majority['Winning party']
majority.dropna().sort('Ratio', ascending=False)
Out[117]:
Absolute majority Winning party Ratio
Badavara Shramikara Raitara Congress Party 3 4 0.750000
Independent 4 9 0.444444
Indian National Congress 40 121 0.330579
Janata Dal (Secular) 9 40 0.225000
Bharatiya Janata Party 8 40 0.200000
Karnataka Jantha Paksha 1 6 0.166667

BSRCP won 3 of its 4 constituencies with an absolute majority. Independents: 4 out of 9. Congress did better at 33% than JD(S) at 22.5% which did better than BJP.

Who lost their deposits?

First, let's get the total votes for a district in a way that aligns with data

In [134]:
data['District'].apply(lambda district: margins.ix[district]).head()
Out[134]:
Candidate1 Party1 Votes1 Rank1 Candidate2 Party2 Votes2 Rank2 Margin Votes % Margin
0 MALIKAYYA VENKAYYA GUTTEDAR Indian National Congress 38093 1 M.Y.PATIL Karnataka Jantha Paksha 32855 2 5238 128611 0.040727
1 MALIKAYYA VENKAYYA GUTTEDAR Indian National Congress 38093 1 M.Y.PATIL Karnataka Jantha Paksha 32855 2 5238 128611 0.040727
2 MALIKAYYA VENKAYYA GUTTEDAR Indian National Congress 38093 1 M.Y.PATIL Karnataka Jantha Paksha 32855 2 5238 128611 0.040727
3 MALIKAYYA VENKAYYA GUTTEDAR Indian National Congress 38093 1 M.Y.PATIL Karnataka Jantha Paksha 32855 2 5238 128611 0.040727
4 MALIKAYYA VENKAYYA GUTTEDAR Indian National Congress 38093 1 M.Y.PATIL Karnataka Jantha Paksha 32855 2 5238 128611 0.040727
In [136]:
data['% votes'] = data['Votes'].astype(float) / data['District'].apply(lambda district: margins['Votes'][district])
data.head()
Out[136]:
District Candidate Party Votes Rank % votes
0 Afzalpur MALIKAYYA VENKAYYA GUTTEDAR Indian National Congress 38093 1 0.296188
1 Afzalpur M.Y.PATIL Karnataka Jantha Paksha 32855 2 0.255460
2 Afzalpur VITTHAL HEROOR Janata Dal (Secular) 22847 3 0.177644
3 Afzalpur GOVIND VISHWANATH BHAT Samajwadi Party 14648 4 0.113894
4 Afzalpur DILIP R. PATIL Bharatiya Janata Party 10347 5 0.080452
In [147]:
sum(data['% votes'] < 1. / 6)
Out[147]:
2413

2,413 candidates lost their deposit of Rs 10,000 (5,000 for SC/ST), out of a total of...

In [148]:
len(data)
Out[148]:
2940

2,940 candidates. Who were the most unfortunate losers?

In [149]:
data[data['% votes'] < 1. / 6].sort('% votes').head(50)
Out[149]:
District Candidate Party Votes Rank % votes
1434 K.r.pura M. RAMAKRISHNA Independent 67 26 0.000335
1433 K.r.pura SRINIVASA Independent 84 25 0.000420
2840 Vijay Nagar DR|| SYED THASADUK AHAMED Independent 64 25 0.000480
2284 Rajaji Nagar P.K PATIL Independent 52 25 0.000482
1432 K.r.pura SARALA BAI Independent 97 24 0.000485
1431 K.r.pura AYUB PASHA Independent 102 23 0.000510
1259 Hosakote ANANDA .M.G Independent 88 11 0.000529
2839 Vijay Nagar SYED ULLA HABIB Independent 73 24 0.000548
1258 Hosakote M.PREMSAGAR Independent 92 10 0.000553
582 Chamrajpet ASGAR-A-MAHEEN.S.M Independent 60 20 0.000557
2754 Tumkur City TOUFEEQ ULLA KHAN Independent 78 14 0.000564
548 Chamaraja NAYAZ AHMED Ambedkar National Congress 62 20 0.000564
1873 Malleshwaram PRABHAKAR Hindusthan Nirman Dal 62 16 0.000572
1843 Mahalakshmi Layout DHANANJAYA .R Independent 86 14 0.000582
1789 Madhugiri T.VENKATAREDDY Independent 87 22 0.000591
581 Chamrajpet B.K.ASLAM KHAN Independent 65 19 0.000604
547 Chamaraja AKEEL AHMEAD Independent 67 19 0.000609
2838 Vijay Nagar SYED SABEER Independent 83 23 0.000623
1430 K.r.pura KESHAV S. HIMALAI Independent 128 22 0.000639
546 Chamaraja ALI AHMED Independent 71 18 0.000646
2283 Rajaji Nagar LAKSHMANA SHETRU.H National People's Party 70 24 0.000649
1429 K.r.pura N. KODANDA REDDY Independent 130 21 0.000649
637 Chickpet M. ADHI MULAM Independent 71 16 0.000652
1872 Malleshwaram RAJESH. P. Independent 71 15 0.000656
636 Chickpet KURAM PASHA Independent 74 15 0.000680
494 Byatarayanapura ABDUL KHADEER Independent 142 16 0.000682
1428 K.r.pura K. SATHYANARAYANA Independent 137 20 0.000684
1651 Krishnaraja H.S.NANJUNDASWAMY Independent 88 19 0.000689
2837 Vijay Nagar C.K.RAVI Bharatiya Dr. B.R.Ambedkar Janta Party 93 22 0.000698
2282 Rajaji Nagar K.T NAGABHUSHAN Janata Dal (United) 76 23 0.000705
493 Byatarayanapura K.SRIDHAR Ambedkar Janatha Party 148 15 0.000710
1944 Mangalore City South HARISH ALVA Janata Dal (United) 96 13 0.000726
2180 Nippani JAY ALIAS JAYAVANT SATAPPA CHOUGULE Independent 112 12 0.000734
580 Chamrajpet C.B.ABDUL SAB Independent 79 18 0.000734
1788 Madhugiri ADHINARAYANAPPA Independent 109 21 0.000740
1787 Madhugiri G.M.NAGARAJU Independent 110 20 0.000747
875 Gandhi Nagar GHOUSE MOHIDDEN Independent 83 14 0.000749
1257 Hosakote B.N.ANANDA Independent 125 9 0.000751
250 Basavanagudi ARUNKUMAR.P. Independent 79 18 0.000762
2540 Shivajinagar M.PRAKASH Independent 70 19 0.000770
1427 K.r.pura P.P.APPANNA Communist Party of India (Marxist-Leninist) ... 155 19 0.000774
2281 Rajaji Nagar VIJAY KUMAR M K Independent 85 22 0.000788
635 Chickpet ASGAR 'A' MAHEEN.S.M Independent 89 14 0.000818
2460 Shanti Nagar PURUSOTHAMAN D.R. Independent 86 15 0.000830
249 Basavanagudi N.HEMANTH KUMAR GOWDA Janata Dal (United) 88 17 0.000849
492 Byatarayanapura D.DEVRAJ Independent 178 14 0.000854
1871 Malleshwaram N. S. SHIVANNA Independent 93 14 0.000859
783 Davanagere North G C PATIL Sarva Janata Party 116 19 0.000863
2179 Nippani JAYAVANT MIRAJAKAR Independent 132 11 0.000864
441 Bijapur City CHANDRU R KALABURGI Independent 103 16 0.000865