Class 12 Informatic Practices Investigatory Project On Paralympic Data Analysis
Class 12 Informatic Practices Investigatory Project On Paralympic Data Analysis
import pandas as pd
import matplotlib.pyplot as plt
print('Welcome to data analysis of Athletes of India at TOKYO Paralympics
2020 created by Divyansh Kala')
location="Athletes Data.csv"
df=pd.read_csv(location)
############################################
# MAIN MENU #
############################################
def menu():
print("\t\t\t +----------------------------------------+")
print("\t\t\t | MAIN MENU |")
print("\t\t\t +----------------------------------------+")
print("\t\t\t |1. Check Data of Athletes |")
print("\t\t\t |2. New Athlete's Registration |")
print("\t\t\t |3. Update Athlete's Details |")
print("\t\t\t |4. Remove Athlete |")
print("\t\t\t |5. Move To Graph Menu |")
print("\t\t\t |6. EXIT |")
print("\t\t\t +----------------------------------------+")
############################################
# All Athletes Data Menu #
############################################
def Data():
print(" +---------------------------------------------------+")
print(" | DATA MENU |")
print(" +---------------------------------------------------+")
print(" |1. All Data of Athletes |")
print(" |2. Record of a particular Athlete |")
print(" |3. Record of Athletes based on Sport |")
print(" |4. Record of Athletes based on State |")
print(" |5. Record of Athletes based on gender |")
print(" |6. Back to main menu |")
print(" +---------------------------------------------------+")
#All Data
def Alldata():
print("\nRECORD OF ALL ATHLETES \n")
dp=pd.read_csv(location, index_col = 0)
print(dp)
print("----------------------------------------")
input("press any key to continue...")
datachoice()
#particular Athlete
def particularAthlete():
print(" +--------------------------------------------+")
print(' |1. Show data of athlete by name |')
print(' |2. Show data of athlete by code |')
print(' |3. back |')
print(" +--------------------------------------------+")
choise=int(input('Enter your choise : '))
if choise == 1:
a=input('enter name of athlete : ')
b=dict(dp['Name'])
for i in range(len(dp)):
if a==b[i]:
print('\nRecord of athlete is as follows:\n')
print(dp.loc[i,:])
print("----------------------------------------")
input("press any key to continue...")
datachoice()
if choise == 2:
b=dict(dp['code'])
a=input('Enter code of athlete : ')
for i in range(len(dp)):
if a==b[i]:
print('\nRecord of athlete is as follows:\n')
print(dp.loc[i,:])
print("----------------------------------------")
input("press any key to continue...")
datachoice()
if choise == 3:
print("----------------------------------------")
datachoice()
else:
particularAthlete()
#based on Sport
def basedonSport():
b=dict(dp['Sport'])
c=input('Enter sport : ')
d=[]
for i in range(len(dp)):
if c==b[i]:
d=d+[i]
print(dp.loc[d,:])
print("----------------------------------------")
input("press any key to continue...")
datachoice()
#based on State
def basedonState():
b=dict(dp['State'])
c=input('Enter state : ')
d=[]
for i in range(len(dp)):
if c==b[i]:
d=d+[i]
print(dp.loc[d,:])
print("----------------------------------------")
input("press any key to continue...")
datachoice()
#based on Gender
def basedonGender():
print(" +-----------------------------------------------+")
print(' |1. Show data of all female athletes |')
print(' |2. Show data of all male athletes |')
print(' |3. back |')
print(" +-----------------------------------------------+")
choise=int(input('enter your choise : '))
if choise == 1:
d1=dict(dp['Gender'])
ind=[]
for i in range(len(d1)):
if 'F' == d1[i]:
ind=ind+[i]
print(dp.loc[ind,:],'\n')
print("----------------------------------------")
input("press any key to continue...")
datachoice()
if choise == 2:
d1=dict(dp['Gender'])
ind=[]
for i in range(len(d1)):
if 'M' == d1[i]:
ind=ind+[i]
print(dp.loc[ind,:],'\n')
print("----------------------------------------")
input("press any key to continue...")
datachoice()
if choise == 3:
print("----------------------------------------")
datachoice()
else:
basedonGender()
#else
def el():
print("Invalid choice")
print("----------------------------------------")
datachoice()
#Data menu
def datachoice():
Data()
d=input("Enter your choice :: ")
if d == 1:
Alldata()
elif d==2:
particularAthlete()
elif d==3:
basedonSport()
elif d==4:
basedonState()
elif d==5:
basedonGender()
elif d==6:
getchoice()
else:
el()
############################################
# NEW ATHLETE REGISTRATION #
############################################
def Register():
rno = len(df)
while True:
print("Please enter Athlete's details...")
code = int(input("Athlete code : "))
if len(df.loc[df['code'] == code])> 0 :
print("\n Duplicate Athlete code, ENTER A VALID ATHLETE CODE \n")
else:
break
def Update():
code = int(input("Enter Athlete code to update: "))
if len(df.loc[df['code'] == code])> 0:
print("Athlete found")
print("Enter details to update")
name = input("Name : ")
sport = input("Sport : ")
finalpos = input("Finalpos : ")
gender = input("Gender : ")
age = input("Age : ")
state = input("State : ")
df.loc[df.loc[df['code'] == code].index,:]=
[code,name,sport,finalpos,gender,age,state]
df.to_csv(location, mode='w')
print("Updated successfully")
print("----------------------------------------")
input("press any key to continue...")
getchoice()
else:
print("Invaid Athlete code")
Update()
############################################
# REMOVE ATHLETE #
############################################
def Remove():
code = int(input("Enter Athlete code to delete: "))
df.drop(df.loc[df['code']==code].index, inplace=True)
df.to_csv(location, mode='w')
print("Athlete successfully removed")
print("----------------------------------------")
input("press any key to continue...")
getchoice()
############################################
# GRAPH MENU #
############################################
def graphmenu():
print(" +--------------------------------------+")
print(" | GRAPH MENU |")
print(" +--------------------------------------+")
print(' |1. No. of Athletes by State |')
print(' |2. No. of Athletes by Age |')
print(' |3. No. of Athletes by Gender |')
print(' |4. No. of Athletes by Sport |')
print(' |5. Back To Main Menu |')
print(" +--------------------------------------+")
def graph():
graphmenu()
ch = int(input('Enter your choice:'))
if ch == 1:
a=df['State'].value_counts()
print(a)
a.plot(kind='bar',width=0.8);
a.plot(kind='line');
plt.ylabel('No. of athletes',fontsize=18)
plt.xlabel('State',fontsize=10)
plt.xticks(rotation='vertical')
plt.title('State wise count')
plt.show()
print("----------------------------------------")
input("press any key to continue...")
graph()
if ch == 2:
a=df['Age']
plt.hist(a,bins=[10,15,20,25,30,35,40,45,45,50,55,60])
plt.xlabel('Age')
plt.ylabel('No. of athletes')
plt.title('Age wise count')
plt.show()
print("----------------------------------------")
input("press any key to continue...")
graph()
if ch == 3:
a=df['Gender'].value_counts()
print(a)
a.plot(kind='bar',width=0.8);
plt.xlabel('Gender')
plt.ylabel('No. of athletes')
plt.title('Gender wise count')
plt.grid(True)
plt.show()
print("----------------------------------------")
input("press any key to continue...")
graph()
if ch == 4:
a=df['Sport'].value_counts()
print(a)
a.plot(kind='bar');
plt.xticks(rotation='vertical')
plt.xlabel('Sport')
plt.ylabel('No. of athletes')
plt.title('Sport wise count')
for index, value in enumerate(a):
plt.text(index,value ,value,ha='center')
plt.show()
print("----------------------------------------")
input("press any key to continue...")
graph()
if ch == 5:
getchoice()
############################################
# GET CHOICE #
############################################
def getchoice():
while True:
menu()
ch = input("\t\t\t Enter Your Choice :: ")
if ch == 1:
datachoice()
elif ch == 2:
print("ATHLETE'S REGISTRATION")
Register()
elif ch==3:
print("ATHLETE UPDATION")
Update()
elif ch==4:
print("ATHLETE DELETION")
Remove()
elif ch==5:
graph()
elif ch == 6:
print("\t\t\t Thank You")
break
else:
print("INVALID CHOICE")
#main
getchoice()