Coding Output CSV
Coding Output CSV
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import os
df1= pd.read_csv('cricket.csv')
def display_record_cricketers():
df1=pd.read_csv('cricket.csv')
if df1.empty:
print("File is empty")
else:
print('')
print(11*'>','Records of cricketers are as
follows',11*'<')
print('')
print("*"*70)
print(df1)
print("*"*70)
input("")
def insert_record_cricketers():
os.system("cls")
df1=pd.read_csv('cricket.csv')
if df1.empty:
position=1
i=0
else:
position=df1.iloc[-1,0]+1
i=df1.index[-1]+1
print('record insertion start')
print(45*'_')
team=input("Enter the team of player :")
print(45*'_')
players=input("Enter the player name :")
print(45*'_')
matchplay=input("Enter the matchplay by player :")
print(45*'_')
win=int(input("Enter the match win :"))
print(45*'_')
lose=int(input("Enter the match lose :"))
print(45*'_')
pid=input("Enter the player id :")
print(45*'_')
df1.loc[i]=[position,team,players,matchplay,win,lose,pi
d]
df1.to_csv('cricket.csv',index=False)
print("Record inserted successfully")
print(45*'_')
input()
def search_record_cricketers():
df1=pd.read_csv('cricket.csv')
if df1.empty:
print("Empty file can't search any record please
insert value first")
else:
print("*"*45)
print("Press 1 to search the record by position:")
print("Press 2 to search the record by players
name:")
print("*"*45)
choice=int(input("Enter your choice:"))
print(45*'_')
if choice==1:
position=int(input("Enter the position:"))
print(45*'_')
df=df1[df1['position']==position]
if df.empty:
print("position not found")
print(45*'_')
else:
print("Record found")
print(45*'v')
print(45*'_')
x=df.index
print(df1.loc[x,
['team','players','matchplay','win','lose']])
print(45*'_')
elif choice==2:
print(45*'_')
players=input("Enter the name of player:")
df=df1[df1['players']==players]
if df.empty:
print("player not found")
print(45*'_')
else:
print("player founded")
print(45*'v')
print(45*'_')
x=df.index
print(df1.loc[x,
['team','players','matchplay','win',
'lose']])
print(45*'_')
else:
print("Please enter valid choice")
input()
def update_record_cricketers():
df1=pd.read_csv('cricket.csv')
print("*"*40)
print("Press 1 to update the record by player id")
print("Press 2 to update the record by position")
print("*"*40)
choice=int(input("Enter your choice:"))
if choice==1:
pid=input("Enter the pid:")
df=df1[df1["pid"]==pid]
if df.empty:
print("Record not found")
else:
x=df.index
c=input("Press y/Y to update name:")
if c=='y' or c=='Y':
n=input("Enter new name:")
df1.loc[x,'players']=n
c=input("Press y/Y to update match played:")
if c=='y' or c=='Y':
print('press "w" for winning a match')
print('press "l" for lossing a match')
c=input("Enter your choice:")
if c=='w' or c=='W' :
df1.loc[x,'matchplay']+=1
df1.loc[x,'win']+=1
elif c=='l' or c=='L' :
df1.loc[x,'matchplay']+=1
df1.loc[x,'lose']+=1
c=input("Press y/Y to update player team:")
if c=='y' or c=='Y':
t=input("Enter new team of player :")
df1.loc[x,'team']=t
print("Record updated successfully")
df1.to_csv('cricket.csv',index=False)
input()
if choice==2:
position=int(input("Enter the position:"))
df=df1[df1["position"]==position]
if df.empty:
print("Record not found")
else:
x=df.index
c=input("Press y/Y to update name:")
if c=='y' or c=='Y':
n=input("Enter new name:")
df1.loc[x,'players']=n
if c=='w' or c=='W' :
df1.loc[x,'matchplay']+=1
df1.loc[x,'win']+=1
elif c=='l' or c=='L' :
df1.loc[x,'matchplay']+=1
df1.loc[x,'lose']+=1
c=input("Press y/Y to update player team:")
if c=='y' or c=='Y':
t=input("Enter new team of player :")
df1.loc[x,'team']=t
if c=='y' or c=='Y':
t=input("Enter new pid of player :")
df1.loc[x,'pid']=t
print("Record updated successfully")
df1.to_csv('cricket.csv',index=False)
input()
def delete_record_cricketers():
df1=pd.read_csv('cricket.csv')
print("*"*40)
print(" Record deletion Menu")
print("Press 1 for removing record by pid")
print("Press 2 for removing record by name")
print("Press 3 for removing record by position")
print("*"*40)
choice=int(input("Enter your choice:"))
if choice==1:
pid=input("Enter the player id :")
df=df1[df1['pid']==pid]
if df.empty:
print("Record not found")
else:
x=df.index
df1.drop(x,axis=0,inplace=True)
print("Record deleted successfully")
df1.to_csv("D:/cricket.csv",index=False)
elif choice==2:
p=input("Enter the name of player :")
df=df1[df1['players']==p]
if df.empty:
print("Record not found")
else:
x=df.index
df1.drop(x,axis=0,inplace=True)
print("Record deleted successfully")
df1.to_csv("D:/cricket.csv",index=False)
elif choice==3:
p=input("Enter the position :")
df=df1[df1['position']==p]
if df.empty:
print("Record not found")
else:
x=df.index
df1.drop(x,axis=0,inplace=True)
if df1.empty:
position=1
i=0
else:
position=df1.iloc[-1,0]+1
i=df1.index[-1]+1
print("Record deleted successfully")
df1.to_csv('cricket.csv',index=False)
else:
print("Please enter valid choice")
print("*"*40)
input()
def visualization_record_cricketers():
print("1. Bar chart for team vs win and lose")
print("2. Line chart for team vs win and lose")
print("3. Histogram for win and lose")
choice = int(input("Enter your choice: "))
if choice == 1:
df1.groupby('team')['win'].sum().plot(kind='bar')
df1.groupby('team')['lose'].sum().plot(kind='bar')
plt.savefig("barchart2.jpg")
plt.show()
elif choice == 2:
df1.groupby('team')['win'].sum().plot(kind='line')
df1.groupby('team')['lose'].sum().plot(kind='line')
plt.savefig("barchart2.jpg")
plt.show()
elif choice == 3:
df1['win'].plot(kind='hist')
df1['lose'].plot(kind='hist')
plt.savefig("barchart2.jpg")
plt.show()
else:
print("Invalid choice")
def ICC_Mans_Test_ranking():
os.system("cls")
print("*"*70)
print("welcome to ICC Mans Test Ranking Menu")
print('')
print(11*'>',' welcome to ICC Mans T20 ranking
Menu',11*'<')
print('')
while True:
print(45*'_')
print('')
print("| Press 1 for Record insertion
|")
print("| Press 2 for Searching of record
|")
print("| Press 3 for Updation of record
|")
print("| Press 4 for Deletion of record
|")
print("| Press 5 for Display of records
|")
print("| Press 6 for Visualization menu
|")
print("| Press 7 for Exit")
print(45*'_')
print('')
print(30*'_')
choice=int(input("Enter your choice:"))
print(30*'_')
if choice==1:
insert_record_cricketers()
print("Back to ICC Mans TEST ranking")
elif choice==2:
search_record_cricketers()
print("Back to ICC Mans TEST ranking")
elif choice==3:
update_record_cricketers()
print('Back to ICC Mans TEST ranking')
elif choice==4:
delete_record_cricketers()
print("Back to ICC Mans TEST ranking")
elif choice==5:
display_record_cricketers()
print("Back to ICC Mans TEST ranking")
elif choice==6:
visualization_record_cricketers()
print("Back to ICC Mans TEST ranking")
elif choice==7:
print("Exiting from ICC Mans TEST ranking")
break
else:
print("Please enter valid choice")
print("*"*70)
input("Press enter key to return to main menu")
def ICC_Mans_ODI_ranking():
os.system("cls")
print("*"*70)
print('')
print(11*'>',' welcome to ICC Mans T20 ranking
Menu','<'*11)
print('')
while True:
print(45*'_')
print('')
print("| Press 1 for Record insertion
|")
print("| Press 2 for Searching of record
|")
print("| Press 3 for Updation of record
|")
print("| Press 4 for Deletion of record
|")
print("| Press 5 for Display of records
|")
print("| Press 6 for Visualization menu
|")
print("| Press 7 for Exit")
print(45*'_')
choice=int(input("Enter your choice:"))
if choice==1:
insert_record_cricketers()
print("Back to ICC Mans ODI ranking")
elif choice==2:
search_record_cricketers()
print("Back to ICC Mans ODI ranking")
elif choice==3:
update_record_cricketers()
print('Back to ICC Mans ODI ranking')
elif choice==4:
delete_record_cricketers()
print("Back to ICC Mans ODI ranking")
elif choice==5:
display_record_cricketers()
print("Back to ICC Mans ODI ranking")
elif choice==6:
visualization_record_cricketers()
print("Back to ICC Mans ODI ranking")
elif choice==7:
print("Exiting from ICC Mans ODI ranking")
break
else:
print("Please enter valid choice")
print("*"*70)
input("Press enter key to return to main menu")
input()
def ICC_Mans_T20_ranking():
os.system("cls")
print("*"*70)
print('')
print(11*'>','welcome to ICC Mans T20 ranking
Menu',11*'<')
print('')
while True:
print(45*'_')
print('')
print("| Press 1 for Record insertion
|")
print("| Press 2 for Searching of record
|")
print("| Press 3 for Updation of record
|")
print("| Press 4 for Deletion of record
|")
print("| Press 5 for Display of records
|")
print("| Press 6 for Visualization menu
|")
print("| Press 7 for Exit")
print(45*'_')
choice=int(input("Enter your choice:"))
if choice==1:
insert_record_cricketers()
print("Back to ICC Mans T20 ranking")
elif choice==2:
search_record_cricketers()
cricket_odi:
cricket_t20:
'icc_rankings.csv:
Output (Screenshots):
*************************************************************************
*********
>>>>>>>>>>> Welcome to icc Mans Management System
<<<<<<<<<<<
_____________________________________________
| Press 1 for ICC Mans TEST ranking |
| Press 2 for ICC Mans ODI ranking |
| Press 3 for ICC Mans T20 ranking |
| Press 4 for Exit |
_____________________________________________
*************************************************************************
*********
Enter your choice: 1
**********************************************************************
welcome to ICC Mans Test Ranking Menu
______________________________
Enter your choice:2
______________________________
*****************************************************
______________________________
Enter your choice:3
______________________________
************************************************
Press 1 to update the record by player id
Press 2 to update the record by position
************************************************
Enter your choice: 1
Enter the pid: av13s
Press y/Y to update name: y
Enter new name: KL Rahul
Press y/Y to update match played: no
Press y/Y to update player team: y
Enter new team of player : india
Record updated successfully
______________________________
Enter your choice: 4
______________________________
************************************************
Record deletion Menu
Press 1 for removing record by pid
Press 2 for removing record by name
Press 3 for removing record by position
************************************************
Enter your choice: 1
Enter the player id : av13s
Record deleted successfully
****************************************
*************************************************************************
*************
position team players matchplay win lose
pid
0 1.0 Australia steve smith 109.0 76.0 33.0
sm90
1 2.0 India virat kohli 115.0 76.0 39.0
vr80
2 3.0 New Zealand kane Williamson 94.0 32.0 62.0
kw78
3 4.0 Pakistan babar azam 47.0 24.0 23.0
ba67
4 5.0 Australia david warner 101.0 54.0 47.0
dw63
*************************************************************************
*************
Back to ICC Mans TEST ranking
_____________________________________________
| Press 1 for Record insertion |
| Press 2 for Searching of record |
| Press 3 for Updation of record |
| Press 4 for Deletion of record |
| Press 5 for Display of records |
| Press 6 for Visualization menu |
| Press 7 for Exit
_____________________________________________
______________________________
Enter your choice:6
______________________________
1. Bar chart for team vs win and lose
2. Line chart for team vs win and lose
3. Histogram for win and lose
Enter your choice: 1
Back to ICC Mans TEST ranking
_____________________________________________
| Press 1 for Record insertion |
| Press 2 for Searching of record |
| Press 3 for Updation of record |
| Press 4 for Deletion of record |
| Press 5 for Display of records |
| Press 6 for Visualization menu |
| Press 7 for Exit
_____________________________________________
______________________________
Enter your choice:6
______________________________
1. Bar chart for team vs win and lose
2. Line chart for team vs win and lose
3. Histogram for win and lose
Enter your choice: 2