COmputer Science Practical
COmputer Science Practical
COMPUTER SCIENCE
CLASS: XII
Under the Guidance of
Mrs.L.Nisha
Submitted by
1. KAVENAYA.R
2. SRINITHI.R
3. CHARANYA DEVI
SRI SWAMY INTERNATIONAL SCHOOL
Affiliated to CBSE, New Delhi Affln. No. 1930458
MASINAYAKANPATTY, AYOTHIYAPATTANAM,
SALEM – 636 103.
PROJECT REPORT
ENTITLED
by _ Reg.No.____
Teacher-In-Charge Principal
Examiners
project. Finally, I thank all who helped me a lot in finalizing the project
6 MYSQL OVERVIEW
7 DATABASE AND
TABLE DESIGN
8 SOURCE CODE
9 OUTPUT
10 BIBLIOGRAPHY
AIM OLYMPIC GAME ANAYSIS
SYSTEM
SOFTWARE PANDAS
MATPLOTLIB
PANDAS:
Pandas is a high-level data manipulation tool developed by Wes McKinney. It is
built on the Numpy package and its key data structure is called the DataFrame.
DataFrames allow you to store and manipulate tabular data in rows of observations
and columns of variables.
MATPLOTBIT:
The matplotlib Python library, developed by John Hunter and many other
contributors, is used to create high-quality graphs, charts, and figures. The library is
extensive and capable of changing very minute details of a figure.
OLYMPIC GAMES ANALYSIS SYSTEM
INTRODUCTION
OLYMPICS HISTORY:
According to historical records, the first ancient Olympic Games can be traced
back to 776 BC. They were dedicated to the Olympian gods and were staged on the
ancient plains of Olympia. They continued for nearly 12 centuries, until Emperor
Theodosius decreed in 393 A.D. that all such "pagan cults" be banned.
HISTORY OF PYTHON
Python was developed by Guido van Rossum in the late eighties and early nineties
at the National Research Institute for Mathematics and Computer Science in the
Netherlands.
Python is derived from many other languages, including ABC, Modula-3, C, C++,
Algol-68, SmallTalk, and Unix shell and other scripting languages.
Python is copyrighted. Like Perl, Python source code is now available under the
GNU General Public License (GPL).
Python is now maintained by a core development team at the institute, although
Guido van Rossum still holds a vital role in directing its progress.
PYTHON FEATURES
1) Easy-to-learn − Python has few keywords, simple structure, and a
clearly defined syntax. This allows the student to pick up the language
quickly.
2) Easy-to-read − Python code is more clearly defined and visible to the eyes.
3) Easy-to-maintain − Python's source code is fairly easy- to-maintain.
4) A broad standard library − Python's bulk of the library is very portable and
cross-platform compatible on UNIX, Windows, and Macintosh.
5) Interactive Mode − Python has support for an interactive mode which
allows interactive testing and debugging of snippets of code.
6) Portable − Python can run on a wide variety of hardware platforms and has
the same interface on all platforms.
7) Extendable − You can add low-level modules to the Python interpreter.
These modules enable programmers to add to or customize their tools to
be more efficient.
8) Databases − Python provides interfaces to all major commercial databases.
9) GUI Programming − Python supports GUI applications that can be created
and ported to many system calls, libraries and windows systems, such as
Windows MFC, Macintosh, and the X Window system of Unix.
10) Scalable − Python provides a better structure and support for large
programs than shell scripting.
MYSQL: OVERVIEW
SQL is the core of a relational database which is used for accessing and managing
the database. By using SQL, you can add, update or delete rows of data, retrieve
subsets of information, modify databases and perform many actions.
DCL (Data Control Language) – It allows you to control access to the database.
Example – Grant or Revoke access permissions.
TCL (Transaction Control Language) – It allows you to deal with the transaction
of the database. Example – Commit, Rollback, Savepoint, Set Transaction.
FEATURES OF MYSQL:
1) Robust Transactional Support
2) Comprehensive Application Development
3) Ease of Management
4) High Performance
5) Open Source & 24 * 7 Support
6) Secure Data Protection
7) High Availability
DATABASE AND TABLE DESIGN
COMMA SEPARATED VALUES (CSV)
EXCEL VIEW:
NOTEPAD VIEW:
#Dataframe used
df=pd.read_csv
def line_chart1():
df=pd.read_csv(
df.sort_values(
df=df.loc[:,['Country','Total Medal']]
df1=df.head(10)
Countries=df1['Country']
Totalmedals=df1['Totalmedals']
plt.plot(Countries,Totalmedals,linestyle=':',color='green',marker='.')
plt.xlabel('Country~~~~~~>',fontsize=12,color='r')
plt.ylabel('Totalmedals~~~~>',fontsize=12,color='r')
plt.title("TOTAL MEDALS WON BY TOP 10 COUNTRIES\
OLYMPIC GAMES DATA ANALYSIS 15
SYSTEM
n",color='blue',fontsize=18)
plt.show()
def line_chart2():
df=pd.read_csv(
df.sort_values(
df=df.loc[:,['Country','SummerTimespart','Wintertimespart']]
df1=df.head(10)
Countries=df1['Country']
STotal=df1['Summertimespart']
WTotal=df1['Wintertimespart']
plt.plot(Countries,Totalmedals,linestyle=':',color='green',marker='.')
plt.xlabel('Country~~~~~~>',fontsize=12,color='r')
plt.ylabel('No of times participitated~~~~>',fontsize=12,color='r')
plt.title("TOTAL NUMBER OF TIMES PARTICIPITATED BY TOP 10
COUNTRIES\n",color='blue',fontsize=18)
plt.legend()
plt.show()
def bar_chart1():
df=pd.read_csv(
df.sort_values(
df=df.loc[:,['Country','SummerTimespart','Wintertimespart']]
df1=df.head(n=10)
x=np.arange(len(df1))
Countries=df1['Country']
Totalgold=df1['Tgoldmedals']
plt.bar(x+0.25,totalgold,width=6,label='Total Number of gold medals by top 10
countries',color='gold')
plt.xticks(x,Countries,rotation=30)
plt.title("OLYMPICS GOLD MEDAL ANALYSIS BY TOP 10 COUNTRIES\
n",color='blue',fontsize=16)
plt.xlabel('Country~~~~~~>',fontsize=12,color='red')
OLYMPIC GAMES DATA ANALYSIS 16
SYSTEM
plt.ylabel('No of Gold Medals~~~~>',fontsize=12,color='red')
plt.grid
plt.legend()
plt.show()
def bar_chart2():
df=pd.read_csv(
df.sort_values(
df=df.loc[:,['Country','SummerTimespart','Wintertimespart']]
df1=df.head(n=10)
x=np.arange(len(df1))
Countries=df1['Country']
Totalgold=df1['Tsilvermedals']
plt.bar(x+0.25,totalsilver,width=6,label='Total Number of silver medals by top 10
countries',color='silver')
plt.xticks(x,Countries,rotation=30)
plt.title("OLYMPICS SILVER MEDAL ANALYSIS BY TOP 10 COUNTRIES\
n",color='blue',fontsize=16)
plt.xlabel('Country~~~~~~>',fontsize=12,color='red')
plt.ylabel('No of Gold Medals~~~~>',fontsize=12,color='red')
plt.grid
plt.legend()
plt.show()
def bar_chart2():
df=pd.read_csv(
df.sort_values(
df=df.loc[:,['Country','SummerTimespart','Wintertimespart']]
df1=df.head(n=10)
x=np.arange(len(df1))
Countries=df1['Country']
Totalgold=df1['Tbronzemedals']
plt.bar(x+0.25,totalbronze,width=6,label='Total Number of bronze medals by top 10
countries',color='peru')
OLYMPIC GAMES DATA ANALYSIS 17
SYSTEM
plt.xticks(x,Countries,rotation=30)
plt.title("OLYMPICS BRONZE MEDAL ANALYSIS BY TOP 10 COUNTRIES\
n",color='blue',fontsize=16)
plt.xlabel('Country~~~~~~>',fontsize=12,color='red')
plt.ylabel('No of Bronze Medals~~~~>',fontsize=12,color='red')
plt.grid
plt.legend()
plt.show()
def pie_chart():
df=pd.read_csv(
df.sum(axis=0,skipna=True)
lst=df.iloc[:,6:9],sum(axis=0)
lst.values.tolist()
clm=['Bronze','Silver','Gold']
plt.title("Medals distribution",color="navy")
plt.pie(lst,labels=clm,autopct='%1.1f%
%",color=['Bronze','Silver','Gold'],shadow=True)
plt.legend(loc='upperleft')
plt.show()
def dbargraph():
df=pd.read_csv(
df.sort_values(
df1=df.head(n=10)
x=np.arange(len(df1))
Countries=df1['Country']
Summermedal=df1['SummerMedal']
Wintermedal=df1['WinterMedal']
plt.bar(x-0.2,Summermedal,width=0.4,label='Total Number of medals by top 10
countries in Summer',color='orangered')
plt.bar(x+0.2,Wintermedal,width=0.4,label='Total Number of medals by top 10
countries in Winter',color='grey')
plt.xticks(x,Countries,rotation=20)
OLYMPIC GAMES DATA ANALYSIS 18
SYSTEM
plt.title("OLYMPICS MEDAL ANALYSIS BY TOP 10 COUNTRIES\
n",color='navy',fontsize=16)
plt.xlabel('Country~~~~~~>',fontsize=12,color='r')
plt.ylabel('No of Medals~~~~>',fontsize=12,color='r')
plt.grid
plt.legend()
plt.show()
def odanalysis():
while True:
print("<.................>")
print("Data Frame Analysis")
print("<.................>")
mn='''1)To print top records by Total medals won
\n 2) To print top records by Total gold medals won
\n 3) To print top records by Total silver medals won
\n 4) To print top records by Total bronze medals won
\n 5) To print Bottom records
\n 6) To print the general information of the dataframe
\n 7) To describe the dataframe
\n 8) To print specified column data
\n 9) To print maximum value for each column
\n 10)To go back to main menu
print(mn)
x=int(input("Enter your choice"))
print("----------x-----------------------x------------------------x-------------x")
df=pd.read_csv(
if x==1:
df=df.sort_values('TotalMedal',ascending = False)
nor=int(input("Enter the number of records to be displayed "))
print("Top",nor,"Records from Dataframe")
print(df.head(nor))
print("----------x-----------------------x------------------------x-------------x")
if x==2:
df=df.sort_values('Tgoldmedal',ascending = False)
nor=int(input("Enter the number of records to be displayed "))
OLYMPIC GAMES DATA ANALYSIS 19
SYSTEM
print("Top",nor,"Records by total number of gold medals")
print(df.head(nor))
print("----------x-----------------------x------------------------x-------------x")
if x==3:
df=df.sort_values('Tsilvermedal',ascending = False)
nor=int(input("Enter the number of records to be displayed "))
print("Top",nor,"Records by total number of silver medals")
print(df.head(nor))
print("----------x-----------------------x------------------------x-------------x")
if x==4:
df=df.sort_values('Tbronzemedal',ascending = False)
nor=int(input("Enter the number of records to be displayed "))
print("Top",nor,"Records by total number of bronze medals")
print(df.head(nor))
print("----------x-----------------------x------------------------x-------------x")
if x==5:
df=df.sort_values('TotalMedal',ascending = False)
nor=int(input("Enter the number of records to be displayed "))
print("Bottom",nor,"Records from Dataframe")
print(df.tail(nor))
print("----------x-----------------------x------------------------x-------------x")
if x==6:
print("Information of Dataframe")
print(df.info())
print("----------x-----------------------x------------------------x-------------x")
if x==7:
print("Describing the basic characteristics of Dataframe")
print(df.describe())
print("----------x-----------------------x------------------------x-------------x")
if x==8:
print("Name of the columns~~>",df.columns)
clm=eval(input("Enter the columns name in a list"))
print(df[clm])
print("----------x-----------------------x------------------------x-------------x")
if x==9:
print("Maximum calue for each column")
print(df.apply(np.max))
print("----------x-----------------------x------------------------x-------------x")
OLYMPIC GAMES DATA ANALYSIS 20
SYSTEM
if x==10:
menu()
break
def read_csv_excel():
ans=True
while ans:
print('''1)Read CSV file and display dataframe
\n2) Read excel file and display dataframe
\n3) Press 3 to go back to main menu
ans=int(input("Enter your choice"))
if ans==1:
df=pd.read_csv(
print(df)
print("Done!")
elif ans==2:
fname=input("Enter filename with PATH and EXTENSIONS(.xls/.xlsx):")
df=pd.read_excel(fname)
print(df)
print("done!")
elif ans==3:
menu()
def imp_exp_sql():
while True:
print("\n\n"+"*"*60)
print("Data transfer to/from MYSQL")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print('''1-Import from MYSQL to creat and display dataframe\
\n\n2-Export from Dataframe to MYSQL\
\n\n3-Press to go back''')
ans=int(input("Enter your choice"))
if ans==1:
sql2df()
OLYMPIC GAMES DATA ANALYSIS 21
SYSTEM
if ans==1:
df2sql()
if ans==3:
menu()
else:
print("Invalid input.Try again")
def sql2df():
db_conn=sqlcn.connect(host='localhost',database='obd',
user='root',password='1244')
fname=input("Enter the tablename:")
db_cursor=db_conn.cursor()
qry='Select*from' +fname+""
db_cursor.execute(qry)
table_rows=db_cursor.fetchall()
for x in tablerows:
print(x)
db_cursor.close()
db_conn.close()
print("....Done!")
def df2sql():
df=pd.read_csv(
df1=df.head(n=11)
print(df1)
db_conn=sqlcn.connect(host='localhost',user='root'
password='1244',database='odb')
tblname=input("Enter the table name:")
db_cursor = db_conn.cursor()
db_cursor.execute("Show Tables Like" +tblname+" ' ")
if db_cursor.fetchone():
db_cursor2=db.conn.cursor()
db_cursor2.execute("Delete from"+tblname)
OLYMPIC GAMES DATA ANALYSIS 22
SYSTEM
db_conn.commit()
for rows,rs in df1.itterrows():
Country=rs[0]
SummerTimesPart=str(rs[1])
SummerTotal=str(rs[2])
WinterTimesPart=str(rs[3])
WinterTOtal=str(rs[4])
TotalTimesPart=str(rs[5])
TBronzeMedal=str(rs[6])
TSilverMedal=str(rs[7])
TGoldMedal=str(rs[8])
TotalMedal=str(rs[9])
qry2="Insert into"+tblname+"values('"+Country+"',"+SummerTimesPart+",\
"+SummerTotal+","+WinterTimesPart+","+WinterTotal+","+TotalTimesPart+",\
"+TBronzeMedal+","+TSilverMedal+","+TGoldMedal+","+TotalMedal+")"
db_cursor2.execute(qry2)
db_conn.commit()
db_cursor2.close()
print("Data transfer from dataframe to mysql>>SUCESSFULL...!")
else:
qry3="Create Table"+tblname+"(Country varchar(20),SummerTimesPart
int,SummerTotal int,\
WinterTimesPart int,WinterTotal int,TotalTimesPart int,TBronzeMedal int,
TSilverMedal int,\
TGoldMedal int,TotalMedal int)"
db_cursor2=db.conn.cursor()
db_cursor2.execute(qry3)
db_conn.commit()
for rows,rs in df1.itterrows():
Country=rs[0]
SummerTimesPart=str(rs[1])
SummerTotal=str(rs[2])
WinterTimesPart=str(rs[3])
WinterTOtal=str(rs[4])
TotalTimesPart=str(rs[5])
TBronzeMedal=str(rs[6])
TSilverMedal=str(rs[7])
TGoldMedal=str(rs[8])
OLYMPIC GAMES DATA ANALYSIS 23
SYSTEM
TotalMedal=str(rs[9])
qry2="Insert into"+tblname+"values('"+Country+"',"+SummerTimesPart+",\
"+SummerTotal+","+WinterTimesPart+","+WinterTotal+","+TotalTimesPart+",\
"+TBronzeMedal+","+TSilverMedal+","+TGoldMedal+","+TotalMedal+")"
db_cursor2.execute(qry2)
db_conn.commit()
db_conn.close()
print("Data transfer from dataframe to mysql>>SUCESSFULL...!")
#Manipulation of data
def manuplt():
df=pd.read_csv(
ans=True
while ans:
print('''Data Manipulation\n
1) Inserting a row
2) Deleting a row
3) Inserting a column
4) Deleting a column
5) Renaming a column
6) Exit to main menu''')
ans=int(input("Enter Your choice"))
if ans==1:
col=df.columns
lst=eval(input("Enter the row values in list:"))
sr=pd.Series(lst,index=col)
row_df1=pd.DataFrame([sr])
df=pd.concat([row_df1,df],ignore_index=True)
print(df)
print("Row added Successfully")
print('~'*30)
elif ans==2:
inp=int(input("Enter the row's index you want to be deleted:")
df1=df.drop(inp,axis=0)
print("~"*30)
print("Dataframe after row index no.",inp,"is deleted..")
print("~"*30)
OLYMPIC GAMES DATA ANALYSIS 24
SYSTEM
print(df1)
print("~"*30)
elif ans==3:
pd.set_option('display.width',500)
pd.set_option('display.max_columns',None)
clname=input('Enter the column name")
inp=int(input("Enter the column index no.\n Where you want to input the
column:'))
df.insert(inp,clname,"Nan")
print(df)
print("~"*30)
elif ans==4:
pd.set_option('display.width',500)
pd.set_option('display.max_columns',None)
print("Dataframe before deleting the column")
print(df)
inp=input("Column name you want to delete")
df=df.drop(inp,axis=1)
print("Dataframe after deleting the column",inp":")
print(df)
print("~"*30)
elif ans==5:
pd.set_option('display.width',500)
pd.set_option('display.max_columns',None)
print("~"*30)
print("Dataframe before deleting the column name/s")
print("~"*30)
print(df)
oldcm=input("Enter the column name you want to rename")
newcm=input("Enter the new column name")
df=df.rename(columns={oldcm:newcm})
print("~"*30)
print("Dataframe after changing the columns name/s")
print("~"*30)
print(df)
print("~"*30)
elif ans==6:
print("Returning to main menu..Done")
OLYMPIC GAMES DATA ANALYSIS 25
SYSTEM
menu()
menu()
OUTPUT
OLYMPIC GAMES DATA ANALYSIS 26
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 27
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 28
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 29
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 30
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 31
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 32
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 33
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 34
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 35
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 36
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 37
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 38
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 39
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 40
SYSTEM
OLYMPIC GAMES DATA ANALYSIS 41
SYSTEM
BIBLIOGRAPHY