0% found this document useful (0 votes)
8 views42 pages

Ip - Project - Electionnew BY

The document contains acknowledgments and a certification for a project titled 'Lok Sabha Election' completed by Khushaan Bagga under the supervision of Mr. Akash Tangri. It also includes Python code for data visualization using various chart types (line, bar, pie, scatter, histogram) with data read from a CSV file. The code allows users to manipulate and visualize election-related data based on voter demographics.

Uploaded by

KhUsHaaN BaGgA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views42 pages

Ip - Project - Electionnew BY

The document contains acknowledgments and a certification for a project titled 'Lok Sabha Election' completed by Khushaan Bagga under the supervision of Mr. Akash Tangri. It also includes Python code for data visualization using various chart types (line, bar, pie, scatter, histogram) with data read from a CSV file. The code allows users to manipulate and visualize election-related data based on voter demographics.

Uploaded by

KhUsHaaN BaGgA
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 42

ACKNOWLEDGEMENT

I wish to express my deep gratitude and sincere


thanks to the Principal Dr. Satwant Kaur Bhullar,
D.A.V. Public School for her encouragement and for
all the facilities she provided for this work. I
sincerely appreciate this magnanimity by taking me
into her fold for which I shall indebted to her. I
extend my hearty thanks to my teacher Mr. Akash
Tangri, who guided me to the successful completion
of this project. I take this opportunity to express
my deep sense of gratitude for his invaluable
guidance, encouragement, motivation, which has
sustained my efforts at all the stages of this
project work.

I cannot forget to offer my sincere thanks to my


parents and friends who helped me in completion of
this project and for their valuable advice and
support.

Thank you!

CERTIFICATE
This is to certify that the Project /
Dissertation entitled Lok Sabha Election
is a bonafide work done by KHUSHAAN BAGGA
of class XII COMMERCE Session 2024-25 in
partial fulfilment of CBSE's AISSCE
Examination and has been carried out under
my direct supervision and guidance. This
report or a similar report on the topic
has not been submitted for any other
examination and does not form a part of
any other course undergone by the
candidate.

Mr. Akash Tangri


CSV FILE
CODE
import matplotlib.pyplot as plt

import pandas as pd

import numpy as np

def main_menu():

print("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+-+-+-+-+-+-+-+-")

print("Read Data from File in Different Way")

print("1. Read complete CSV file")

print("2. Reading complete file without index")

print("====================================
================"

print("Data Visualization")

print("3. Line Chart")

print("4. Bar Plot")

print("5. Pie Chart")

print("6. Scatter Chart")

print("7. Histogram")

print("====================================
================")
print("Apply data Manipulation in the records of CSV
file")
print("8. Sorting the data as per your choice")
print("9. Read Top and Bottom records from file as per
requirment")
print("10. Make the copy of CSV file")
print("11. Read the Specific columns")
print("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+-+-+-+-+-+-+-++-+-+-+-+-+-+-+-+-+-+-+-+-+")

main_menu()

def Read_CSV():
print("Reading Data from CSV File")
df=pd.read_csv("D:/Data.csv")
df.dropna(inplace=True)
print(df)

def no_index():
print("Reading Data from CSV file without index value")
df=pd.read_csv("D:/Data.csv",index_col=0)
df.dropna(inplace=True)
print(df)
def Line_Plot():
df=pd.read_csv("D:/Data.csv")
st=df['State']
te=df['Total Electors']
tav=df['Total Actual Votes']
ma=df['Males Voters']
fe=df['Females Voters']
ot=df['Others Voters']
tv=df['Total Voters']
plt.xlabel("states")
plt.xticks(rotation='vertical')
print("Select Specific Line Chart as given below:")
print("Press 1 to Print the Data for States vs Total
Electors")
print("Press 2 to Print the Data for States vs Total Actual
Votes")
print("Press 3 to Print the Data for States vs Males
Voters")
print("Press 4 to Print the Data for States vs Females
Voters")
print("Press 5 to Print the Data for States vs Others
Voters")
print("Press 6 to Print the Data for States vs Total Voters")
print("Press 7 to Merge all the data in one Line Chart")

op=int(input("Enter Your Choice:"))

if op==1:
plt.ylabel("Total Electors")
plt.xlabel("States")
plt.title("States vs Total Electors")
plt.plot(st,te,color='cornflowerblue',marker='o',markeredg
ecolor='red',markersize=7,label="States Wise Total
Electors")
plt.legend(loc='upper center')
plt.show()
elif op==2:
plt.ylabel("Total Actual Votes")
plt.xlabel("States")
plt.title("States vs Total Actual Votes")
plt.plot(st,tav,color='r',marker='D',markeredgecolor='blue'
,markersize =7,linestyle='dashdot',label="States Wise
Total Actual Votes")
plt.legend()
plt.show()
elif op==3:
plt.ylabel("Males Voters")
plt.xlabel("States")
plt.title("States vs Males Voters")

plt.plot(st,ma,color='g',marker='h',markeredgecolor='Mag
enta',markersize=7,linestyle='dotted',label="States Wise
Males Voters")
plt.legend()
plt.show()
elif op==4:
plt.ylabel("Females Voters")
plt.xlabel("States")
plt.title("State vs Females Voters")
plt.plot(st,fe,color='m',marker='p',markeredgecolor='Cyan
',markersize=7,linestyle='dashed',label="States Wise
Females Voters")
plt.legend()
plt.show()
elif op==5:
plt.ylabel("Others Voters")
plt.xlabel("States")
plt.title("State vs Others Voters")

plt.plot(st,ot,color='c',marker='2',markeredgecolor='Mage
nta',markersize=7,linestyle='dotted',label="States Wise
Others Voters")
plt.legend()
plt.show()
elif op==6:
plt.ylabel("Total Voters")
plt.xlabel("States")
plt.title("State vs Total Voters")

plt.plot(st,tv,color='y',marker='*',markeredgecolor='Green
',markersize=7,linestyle='dashdot',label="States Wise
Total Voters")
plt.legend()
plt.show()
elif op==7:
plt.ylabel("Number of Voters")
plt.xlabel("States")
plt.title("Merge Data")
plt.plot(st,te,color='b',label="States Wise Total Electors")
plt.plot(st,tav,color='r',label="States Wise Total Actual
Votes")
plt.plot(st,ma,color='g',label="States Wise Males Voters")
plt.plot(st,fe,color='m',label="States Wise Females
Voters")
plt.plot(st,ot,color='c',label="States Wise Others Voters")
plt.plot(st,tv,color='y',label="States Wise Total Voters")
plt.legend()
plt.show()
else:
print("Enter Valid Input")

def Bar_Plot():
df=pd.read_csv("D:/Data.csv")
df.dropna(inplace=True)
st=df['State']
te=df['Total Electors']
tav=df['Total Actual Votes']
ma=df['Males Voters']
fe=df['Females Voters']
ot=df['Others Voters']
tv=df['Total Voters']
plt.xlabel("states")
plt.xticks(rotation='vertical')

print("Select Specific Bar Chart as given below:")


print("Press 1 to Print the Data for States vs Total
Electors")
print("Press 2 to Print the Data for States vs Total Actual
Votes")
print("Press 3 to Print the Data for States vs Males
Voters")
print("Press 4 to Print the Data for States vs Females
Voters")
print("Press 5 to Print the Data for States vs Others
Voters")
print("Press 6 to Print the Data for States vs Total Voters")
print("Press 7 to print all the data in form of Stack Bar
Chart")
print("press 8 to print all the data in form of Multi Bar
Chart")
op=int(input("Enter Your Choice:"))

if op==1:
plt.ylabel("Total Electors")
plt.xlabel("States")
plt.title("States vs Total Electors")
plt.bar(st,te,color='deepskyblue',edgecolor='navy',label="
States Wise Total Electors")
plt.legend()
plt.show()
elif op==2:
plt.ylabel("Total Actual Votes")
plt.xlabel("States")
plt.title("States vs Total Actual Votes")

plt.bar(st,tav,color='mediumslateblue',edgecolor='crimson
',label="Sta tes Wise Total Actual Votes")
plt.legend()
plt.show()
elif op==3:
plt.ylabel("Males Voters")
plt.xlabel("States")
plt.title("States vs Males Voters")
plt.bar(st,ma,color='chartreuse',edgecolor='teal',label="St
ates Wise Males Voters")
plt.legend()
plt.show()
elif op==4:
plt.ylabel("Females Voters")
plt.xlabel("States")
plt.title("States vs Females Voters")
plt.bar(st,fe,color='lightcoral',edgecolor='royalblue',label
="States Wise Females Voters")
plt.legend()
plt.show()
elif op==5:
plt.ylabel("Others Voters")
plt.xlabel("States")
plt.title("States vs Others Voters")
plt.bar(st,ot,color='gray',edgecolor='black',label="States
Wise Others Voters")
plt.legend()
plt.show()
elif op==6:
plt.ylabel("Total Voters")
plt.xlabel("States")
plt.title("States vs Total Voters")
plt.bar(st,tv,color='navy',edgecolor='tomato',label="States
Wise Total Voters")
plt.legend()
plt.show()
elif op==7:
plt.title("Stack Bar Chart")
plt.xlabel("States")
plt.bar(st,te,width=0.2,color='b',label="States Wise Total
Electors")
plt.bar(st,tav,width=0.2,color='r',label="States Wise Total
Actual Votes")
plt.bar(st,ma,width=0.2,color='g',label="States Wise
Males Voters")
plt.bar(st,fe,width=0.2,color='m',label="States Wise
Females Voters")
plt.bar(st,ot,width=0.2,color='c',label="States Wise
Others Voters")
plt.bar(st,tv,width=0.2,color='y',label="States Wise Total
Voters")
plt.legend()
plt.show()
elif op==8:
ind=np.arange(len(st))
width=0.25
plt.title("Multi Bar Chart")
plt.xlabel("States")
plt.bar(ind,te,width,color='b',label="States Wise Total
Electors")
plt.bar(ind+0.25,tav,width,color='r',label="States Wise
Total Actual Votes")
plt.bar(ind+0.50,ma,width,color='g',label="States Wise
Males Voters")
plt.bar(ind+0.75,fe,width,color='m',label="States Wise
Females Voters")
plt.bar(ind+1.0,ot,width,color='c',label="States Wise
Others Voters")
plt.bar(ind+1.25,tv,width,color='y',label="States Wise
Total Voters")
plt.legend()
plt.show()
else:
print("Enter Valid Input")

def Pie_Plot():
df=pd.read_csv("D:/Data.csv")
df.dropna(inplace=True)
st=df['State']
te=df['Total Electors']
tav=df['Total Actual Votes']
ma=df['Males Voters']
fe=df['Females Voters']
ot=df['Others Voters']
tv=df['Total Voters']

print("Select Specific Pie Chart as given below:")


print("Press 1 to Print the Data for State vs Total Electors
")
print("Press 2 to Print the Data for State vs Total Actual
Votes")
print("Press 3 to Print the Data for State vs Males
Voters")
print("Press 4 to Print the Data for State vs Females
Voters")
print("Press 5 to Print the Data for State vs Others
Voters")
print("Press 6 to Print the Data for State vs Total Voters")

op=int(input("Enter Your Choice:"))

if op==1:
plt.title("States Wise Total Electors")
plt.pie(te,labels=st,autopct="%3d%%")
plt.show()
elif op==2:
plt.title("States Wise Total Actual Votes")
plt.pie(tav,labels=st,autopct="%3d%%")
plt.show()
elif op==3:
plt.title("States Wise Males Voters")
plt.pie(ma,labels=st,autopct="%3d%%")
plt.show()
elif op==4:
plt.title("States Wise Females Voters")
plt.pie(fe,labels=st,autopct="%3d%%")
plt.show()
elif op==5:
plt.title("States Wise Others Voters")
plt.pie(ot,labels=st,autopct="%3d%%")
plt.show()
elif op==6:
plt.title("States Wise Total Voters")
plt.pie(tv,labels=st,autopct="%3d%%")
plt.show()
else:
print("Enter Valid Input")

def Scatter_Chart():
df=pd.read_csv("D:/Data.csv")
df.dropna(inplace=True)
st=df['State']
te=df['Total Electors']
tav=df['Total Actual Votes']
ma=df['Males Voters']
fe=df['Females Voters']
ot=df['Others Voters']
tv=df['Total Voters']

print("Select Specific Scatter Chart as given below:")


print("Press 1 to Print the Data for State vs Total
Electors")
print("Press 2 to Print the Data for State vs Total Actual
Votes")
print("Press 3 to Print the Data for State vs Males
Voters")
print("Press 4 to Print the Data for State vs Females
Voters")
print("Press 5 to Print the Data for State vs Others
Voters")
print("Press 6 to Print the Data for State vs Total Voters")
print("Press 7 to Merge all the data in one Scatter Chart")
op=int(input("Enter Your Choice:"))

if op==1:
ax=plt.gca()
ax.scatter(st,te,color='b',label="States Wise Total
Electors")
plt.xlabel("States")
plt.ylabel("Total Electors")
plt.xticks(rotation='vertical')
plt.title("States vs Total Electors")
plt.legend()
plt.show()
elif op==2:
ax=plt.gca()
ax.scatter(st,tav,color='r',label="States Wise Total Actual
Votes")
plt.xlabel("States")
plt.ylabel("Total Actual Votes")
plt.xticks(rotation='vertical')
plt.title("States vs Total Actual Votes")
plt.legend()
plt.show()
elif op==3:
ax=plt.gca()
ax.scatter(st,ma,color='g',label="States Wise Males
Voters")
plt.xlabel("States")
plt.ylabel("Males Voters")
plt.xticks(rotation='vertical')
plt.title("States vs Males Voters")
plt.legend()
plt.show()
elif op==4:
ax=plt.gca()
ax.scatter(st,fe,color='deepskyblue',label="States Wise
Females Voters")
plt.xlabel("States")
plt.ylabel("Females Voters")
plt.xticks(rotation='vertical')
plt.title("States vs Females Voters")
plt.legend()
plt.show()
elif op==5:
ax=plt.gca()
ax.scatter(st,ot,color='sandybrown',label="States Wise
Others Voters")
plt.xlabel("States")
plt.ylabel("Others Voters")
plt.xticks(rotation='vertical')
plt.title("States vs Others Voters")
plt.legend()
plt.show()
elif op==6:
ax=plt.gca()
ax.scatter(st,tv,color='m',label="States Wise Total
Voters")
plt.xlabel("States")
plt.ylabel("Total Voters")
plt.xticks(rotation='vertical')
plt.title("States vs Total Voters")
plt.legend()
plt.show()
elif op==7:
ax=plt.gca()
ax.scatter(st,te,color='b',label="States Wise Total
Electors")
ax.scatter(st,tav,color='r',label="States Wise Total Actual
Votes")
ax.scatter(st,ma,color='g',label="States Wise Males
Voters")
ax.scatter(st,fe,color='deepskyblue',label="States Wise
Females Voters")
ax.scatter(st,ot,color='sandybrown',label="States Wise
Others Voters")
ax.scatter(st,tv,color='m',label="States Wise Total
Voters")
plt.xlabel("States")
plt.xticks(rotation='vertical')
plt.title("Complete Scatter Chart")
plt.legend()
plt.show()
else:
print("Enter Valid Input")

def Histogram():
df=pd.read_csv("D:/Data.csv")
df.dropna(inplace=True)
st=df['State']
te=df['Total Electors']
tav=df['Total Actual Votes']
ma=df['Males Voters']
fe=df['Females Voters']
ot=df['Others Voters']
tv=df['Total Voters']
plt.xlabel("states")
plt.xticks(rotation='vertical')

print("Select Specific Histogram as given below:")


print("Press 1 to Print the Data for States vs Total
Electors")
print("Press 2 to Print the Data for States vs Total Actual
Votes")
print("Press 3 to Print the Data for States vs Males
Voters")
print("Press 4 to Print the Data for States vs Females
Voters")
print("Press 5 to Print the Data for States vs Others
Voters")
print("Press 6 to Print the Data for States vs Total Voters")

op=int(input("Enter Your Choice:"))

if op==1:
plt.ylabel("Total Electors")
plt.xlabel("States")
plt.title("States vs Total Electors")
plt.hist(te,color='darkslategrey',edgecolor='paleturquoise',
label="Stat e Wise Total Electors")
plt.show()
elif op==2:
plt.ylabel("Total Actual Votes")
plt.title("States vs Total Actual Votes")
plt.xlabel("States")
plt.hist(tav,color='greenyellow',edgecolor='purple',label="
States Wise Total Actual Votes")
plt.show()
elif op==3:
plt.ylabel("Males Voters")
plt.title("States vs Males Voters")
plt.xlabel("States")
plt.hist(ma,color='gold',edgecolor='orangered',label="Stat
es Wise Males Voters")
plt.show()
elif op==4:
plt.ylabel("Females Voters")
plt.title("States vs Females Voters")
plt.xlabel("States")
plt.hist(fe,color='lightskyblue',edgecolor='fuchsia',label="
States Wise Females Voters")
plt.show()
elif op==5:
plt.ylabel("Others Voters")
plt.title("States vs Others Voters")
plt.xlabel("States")
plt.hist(ot,color='darkviolet',edgecolor='limegreen',label=
"States Wise Others Voters")
plt.show()
elif op==6:
plt.ylabel("Total Voters")
plt.title("States vs Total Voters")
plt.xlabel("States")
plt.hist(tv,color='dodgerblue',edgecolor='black',label="Sta
tes Wise Total Voters")
plt.show()
else:
print("Enter Valid Input")

def Data_Sorting():
df=pd.read_csv("D:/Data.csv")
df.dropna(inplace=True)

print("Press 1 to arrange the record as per the States


Name")
print("Press 2 to arrange the record as per the Total
Electors")
print("Press 3 to arrange the record as per the Total Actual
Votes")
print("Press 4 to arrange the record as per the Males
Voters")
print("Press 5 to arrange the record as per the Females
Voters")
print("Press 6 to arrange the record as per the Others
Voters")
print("Press 7 to arrange the record as per the Total
Voters")

op=int(input("Enter Your Choice:"))


if op==1:
df.sort_values(["State"],inplace=True)
print(df)
elif op==2:
df.sort_values(["Total Electors"],inplace=True)
print(df)
elif op==3:
df.sort_values(["Total Actual Votes"],inplace=True)
print(df)
elif op==4:
df.sort_values(["Males Voters"],inplace=True)
print(df)
elif op==5:
df.sort_values(["Females Voters"],inplace=True)
print(df)
elif op==6:
df.sort_values(["Others Voters"],inplace=True)
print(df)
elif op==7:
df.sort_values(["Total Voters"],inplace=True)
print(df)
else:
print("Enter Valid Input")

def Top_Bottom_Selected_Records():
df=pd.read_csv("D:/Data.csv",index_col=0)
top=int(input("How Many records to display from
Top:"))
print("Frist",top,"records")
print(df.head(top))
bottom=int(input("How Many records to display from
Bottom:"))
print("Last",bottom,"records")
print(df.tail(bottom))
def Duplicate():
print("Duplicate the file with new file")
df=pd.read_csv("D:/Data.csv")
df.to_csv("D:/Datanew.csv")
print("Data from the New File")
print(df)

def Specific_Column():

print("Press 1 to Print the Data for State and Total


Electors")

print("Press 2 to Print the Data for State and Total Actual


Votes")

print("Press 3 to Print the Data for State and Males


Voters")

print("Press 4 to Print the Data for State and Females


Voters")

print("Press 5 to Print the Data for State and Others


Voters")

print("Press 6 to Print the Data for State and Total


Voters")

op=int(input("Enter Your Choice:"))

if op==1:

print("Reading Specific Column From CSV File")

df=pd.read_csv("D:/Data.csv",usecols=['State','Total
Electors'],index_col=0)

print(df)
elif op==2:

print("Reading Specific Column From CSV File")

df=pd.read_csv("D:/Data.csv",usecols=['State','Total
Actual Votes'],index_col=0)

print(df)

elif op==3:

print("Reading Specific Column From CSV File")

df=pd.read_csv("D:/Data.csv",usecols=['State','Males
Voters'],index_col=0)

print(df)

elif op==4:

print("Reading Specific Column From CSV File")

df=pd.read_csv("D:/Data.csv",usecols=['State','Females
Voters'],index_col=0)

print(df)

elif op==5:

print("Reading Specific Column From CSV File")

df=pd.read_csv("D:/Data.csv",usecols=['State','Others
Voters'],index_col=0)

print(df)

elif op==6:

print("Reading Specific Column From CSV File")

df=pd.read_csv("D:/Data.csv",usecols=['State','Total
Voters'],index_col=0)

print(df)
else:

print("Enter Valid Input")

option=int(input("Enter Your Choice="))

if option==1:

Read_CSV()

elif option==2:

no_index()

elif option==3:

Line_Plot()

elif option==4:

Bar_Plot()

elif option==5:

Pie_Plot()

elif option==6:

Scatter_Chart()

elif option==7:

Histogram()

elif option==8:

Data_Sorting()

elif option==9:

Top_Bottom_Selected_Records()

elif option==10:

Duplicate()
elif option==11:

Specific_Column()

else:

print("enter valid input")

Figure 3.1 Line Chart

States vs Total Electors

Figure 3.2 Line Chart States vs Total Actual Votes


Figure 3.3 Line Chart States vs Male Voters

Figure 3.4 Line Chart States vs Female Voters


Figure 3.5 Line Chart States vs Others Voters

Figure 3.6 Line Chart States vs Total Voters


Figure 3.7 Merge Chart

Figure 4.1 Bar Chart States vs Total Electors


Figure 4.2 Bar Chart States vs Total Actual Votes

Figure 4.3 Bar Chart States vs Male Voters


Figure 4.4 Bar Chart States vs Female Voters

Figure 4.5 Bar Chart States vs Others Voters


Figure 4.6 Bar Chart States vs Total Voters

Figure 4.7 Stack Bar Chart


Figure 4.8 Multi Bar Chart
Figure 5.1 Pie Chart States vs Total Electors
Figure 5.2 Pie Chart States vs Total Actual Votes

Figure 6.1 Scatter Chart States vs Total Electors

Figure 6.2 Scatter Chart States vs Total Actual Votes


Figure 6.3 Scatter Chart States vs Male Voters

Figure 6.4 Scatter Chart States vs Female Voters


Figure 6.5 Scatter Chart States vs Others Voters

Figure 6.6 Scatter Chart States vs Total Voters


Figure 6.7 Complete Scatter Chart

Figure 7.1 Histogram States vs Total Electors


Figure 7.2 Histogram States vs Total Actual Votes

Figure 7.3 Histogram States vs Male Voters


Figure 7.4 Histogram States vs Female Voters

Figure 7.5 Histogram States vs Others Voters


Figure 7.6 Histogram States vs Total Voters

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy