Ip - Project - Electionnew BY
Ip - Project - Electionnew BY
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.
import pandas as pd
import numpy as np
def main_menu():
print("+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
+-+-+-+-+-+-+-+-")
print("====================================
================"
print("Data Visualization")
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")
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')
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']
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']
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')
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)
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():
if op==1:
df=pd.read_csv("D:/Data.csv",usecols=['State','Total
Electors'],index_col=0)
print(df)
elif op==2:
df=pd.read_csv("D:/Data.csv",usecols=['State','Total
Actual Votes'],index_col=0)
print(df)
elif op==3:
df=pd.read_csv("D:/Data.csv",usecols=['State','Males
Voters'],index_col=0)
print(df)
elif op==4:
df=pd.read_csv("D:/Data.csv",usecols=['State','Females
Voters'],index_col=0)
print(df)
elif op==5:
df=pd.read_csv("D:/Data.csv",usecols=['State','Others
Voters'],index_col=0)
print(df)
elif op==6:
df=pd.read_csv("D:/Data.csv",usecols=['State','Total
Voters'],index_col=0)
print(df)
else:
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: