# Election analysis 2021: West Bengal

May 12 · 4 min read

The most important story in Indian media for the last 3 months was that of the Bengal elections since the Modi govt gave it all they had to win it. Despite their consistent efforts, they failed to even cross a 3 figure mark.

# Analysis

We shall analyze the election data. I have downloaded my data from this website.

# All Candidates Data

We have downloaded the data, before starting the analysis I will try to understand the data better.

`import pyforestdf=pd.read_csv("west_bengal/west_bengal.csv")`
`df.info()`

# Most Imp Constituency

`constituency = df['constituency'].value_counts().head(10)fig = px.bar(x=constituency.index, y=constituency, height=500, width=700, title='Top 10 Constituency Name')fig.update_traces(marker = dict(                            line = dict(color = "rgb(20, 20, 20)", width = 2)))fig.show()`

# Criminal Cases

`df.groupby('party')['criminal_cases'].sum().reset_index().sort_values(by='criminal_cases', ascending=False).head(15).style.background_gradient(cmap='Blues')`
`crime = df[df['criminal_cases']!=0]crime =crime.groupby(['candidate','party'])['criminal_cases'].sum().reset_index().sort_values(by='criminal_cases',ascending=False)crime.style.background_gradient(cmap='pink_r')`

Observation: BJP candidates have the highest number of criminal cases on them. 1 of the BJP candidate have 27 total cases on him and is still fighting in the election.

# Education

`fig = px.pie(values=df['education'].value_counts(), names=df['education'].value_counts().index, height=500)fig.update_traces(pull=[0.0,0.0,0.2,0.0], hole=.3, hoverinfo="label+percent", marker=dict(colors=line_colors, line=dict(color='black', width=2)))fig['layout'].update(title='Education Distribution', titlefont_size=20)fig.show()`
`a4_dims = (19, 7.5)fig, ax = plt.subplots(figsize=a4_dims)sns.set(style='darkgrid')sns.countplot(x ='education',               data = df ,               order = df['education'].value_counts().index ,              palette ="prism")fig.suptitle('Education Distribution using Bar Chart', fontsize=25)plt.show()`

# Total Assets

`df.groupby('party')['total_assets'].sum().reset_index().sort_values(by='total_assets',ascending=False)`

Observation: AITC owns the highest amount of assets followed by BJP.

# Election Winners 2021 Bengal

The data can be collected from the same website again. The earlier analysis for all the candidates that fought elections. We will be discussing the election results and winner candidates.

`bengal=pd.read_csv("bengal_votes.csv")`
`party_winner = bengal['Party'].value_counts()fig = px.bar(x=party_winner.index, y=party_winner, height=600, width=1100, title='Party Distribution', text=(bengal['Party'].value_counts()/len(bengal['Party'])*100))fig.update_traces(textposition='outside',texttemplate='%{text:.4s}%',marker = dict(color = "rgba(255, 0, 0, 0.7)",                            line = dict(color = "rgb(20, 20, 20)", width = 2)))fig.show()`

# Criminal cases

`bengal.groupby("Party")["Criminal Case"].sum().reset_index().sort_values(by="Criminal Case", ascending=False).style.background_gradient(cmap='Blues')`
`crime = bengal[bengal['Criminal Case']!=0]crime =crime.groupby(['Candidate','Party'])['Criminal Case'].sum().reset_index().sort_values(by='Criminal Case',ascending=False)crime.style.background_gradient(cmap='pink_r')`

Observation: of the winning members AITC has the highest criminal cases which are obvious since they have 202 members who won in the elections. Mukul Roy from BJP has the highest cases individually.

# Education

`fig = px.pie(values=bengal['Education'].value_counts(), names=bengal['Education'].value_counts().index, height=500)fig.update_traces(pull=[0.0,0.0,0.2,0.0], hole=.3, hoverinfo="label+percent", marker=dict(colors=line_colors, line=dict(color='black', width=2)))fig['layout'].update(title='Education Distribution', titlefont_size=20)fig.show()`
`a4_dims = (19, 7.5)fig, ax = plt.subplots(figsize=a4_dims)sns.set(style='darkgrid')sns.countplot(x ='Education',               data = bengal ,               order = bengal['Education'].value_counts().index ,              palette ="prism")fig.suptitle('Education Distribution using Bar Chart', fontsize=25)plt.show()`

Observation: Highest number of winning candidates(24%) are graduates. 21% of the winning candidates are just 12th pass.

# Defectors from re-contesting members

For the data, I will use the website. A lot of candidates shifted parties this time and as media told us that a lot of a lot TMC members had joined BJP before elections. So that’s what I wanted to find out

`defectors.value_counts("Remarks").reset_index().style.background_gradient(cmap="Pastel2")`

Observation: More people from INC have defected than AITC.

## Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data…

## Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

Written by

## Anmol Hans

Geopolitics and Data Science enthusiast.

## Analytics Vidhya

Analytics Vidhya is a community of Analytics and Data Science professionals. We are building the next-gen data science ecosystem https://www.analyticsvidhya.com

## LDA(latent Dirichlet association) for non-statisticians.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app