Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added assignment 5 #89

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions Introduction-to-Data-Science/Week-3/Saurabh/assignment4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
Ans-1:
A class describes the contents of the objects that belong to it,it describes an aggregate of data fields (called instance variables), and defines the operations (called methods).

Ans-2:
An object is an element (or instance) of a class.Objects have the behaviors of their class.

Ans-3:
An object exhibits the property and behaviors defined by its class.

Ans-4:
class ClassName:
<statement-1>
.
.
.
<statement-N>

Ans-5:
A method is a function that takes a class instance as its first parameter.

Ans-6:
self is needed to distinguish between instances(objects).

Ans-7:
__init__ is a special method in Python classes, it is the constructor method for a class.

Ans-8:
With the help of inheritance,we don,t need to write a code of child class again which prevents in code duplication.

Ans-9:
import random

class card():
suit={"Hearts":['A',2,3,4,5,6,7,8,9,10,'J','Q','K'],"Diamonds":['A',2,3,4,5,6,7,8,9,10,'J','Q','K'],"Clubs":['A',2,3,4,5,6,7,8,9,10,'J','Q','K'],"Spades":['A',2,3,4,5,6,7,8,9,10,'J','Q','K']}
class deck_of_card(card):
def shuffle_(self):
if(len(card().suit["Hearts"])+len(card().suit["Diamonds"])+len(card().suit["Clubs"])+len(card().suit["Spades"])==52 ):
print("ALL CARD PRESENT")
for i in card().suit:
random.shuffle(card().suit[i])
def deal(self,card_suit,card_no):
print("dealt card is ",card_suit,card_no)
card().suit[card_suit].remove(card_no)


Ans-10:
class person:
def __init__(self,fname,lname,phone_no,*email):
self.first_name=fname
self.last_name=lname
self.phone_no=phone_no
self.email=email
class address_book(person):
addbook=[]
def __init__(self,info):
self.add_contact(info)
def add_contact(self,info):
self.addbook.append(info)
def lookup_contact(self,lname,fname="none"):
for i in self.addbook:
if(fname=="none"):
if(i.last_name==lname):
print(i.first_name,i.last_name,i.phone_no,i.email)
else:
if(i.last_name==lname and i.first_name==fname):
print(i.first_name,i.last_name,i.phone_no,i.email)



33 changes: 33 additions & 0 deletions Introduction-to-Data-Science/Week-3/Saurabh/assignment5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
Ans-1
opens a file for both appending and reading in binary format.

Ans-2
Every file when read,transfers data to an intermediate bufferbefore it can be accessed by python.

Ans-3
code:
try:
file=open("file.txt","r")
a=1/0
except IOError:
print("Error: file doesn't exist")
except ZeroDivisionError:
print("Zero Division Error")
except SyntaxError:
print("Syntax Error")




Ans-4
code:
file=open("qn4.txt",'r')
my_list=[]
while True:
line=file.readline()
my_list.append(line)
if not line:
break
for i in range(len(my_list)-1,-1,-1):
print(my_list[i])

94 changes: 94 additions & 0 deletions Introduction-to-Data-Science/Week-5/SAURABH/ASSIGNMENT6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
Ans-1:
import numpy as np
import pandas as pd

player_match=pd.read_csv("DIM_PLAYER_MATCH.csv",delimiter=',',encoding=":ISO-8859-1",skiprows=[1])

per={}

for i in range (2008,2018):
young=player_match.loc[(player_match.Season_year ==i) & (player_match.Age_As_on_match <25)]['Player_Id'].unique()
allp=player_match.loc[(player_match.Season_year == i)]['Player_Id'].unique()
per[i]=len(young)/len(allp)*100
print(per)

teamn={}
for i in range (2008,2018):
max=0
teamname='NULL'
for team in player_match.Player_team.unique():
young=player_match.loc[(player_match.Player_team ==team) & (player_match.Age_As_on_match <25) & (player_match.Season_year==i)]['Player_Id'].unique()
if(len(young)>max):
max=len(young)
teamname=team
teamn[i]=teamname
print(teamn)

award=player_match.loc[(player_match.Age_As_on_match <25)&(player_match.is_manofThematch==1)]['Player_Id'].unique()
total=player_match.loc[(player_match.is_manofThematch==1)]['Player_Id'].unique()
print(len(award)/len(total)*100)

Ans-2:
player_match['Batting_hand'] = player_match['Batting_hand'].map({'Right-hand bat':'Right-handed',
'\xa0Right-hand bat':'Right-handed',
'Left-hand bat' : 'Left-handed',
'\xa0Left-hand bat' : 'Left-handed'})
right=player_match.loc[(player_match.Batting_hand=='Right-handed')&(player_match.is_manofThematch==1)]
left=player_match.loc[(player_match.Batting_hand=='Left-handed')&(player_match.is_manofThematch==1)]
print("No. of times Right handed player won Man of the Match:",len(right))
print("No. of times Left handed player won Man of the Match:",len(left))
player_match['Bowling_skill']=player_match['Bowling_skill'].map({
'Right-arm offbreak':'spin','Right-arm medium':'pace',
'Right-arm fast-medium':'pace','Left-arm fast-medium':'pace','Legbreak googly':'spin',
'Right-arm medium-fast':'pace',
'Slow left-arm orthodox':'spin','Right-arm fast':'pace',
'Slow left-arm chinaman':'spin','Left-arm medium-fast':'pace',
'Legbreak':'Spin','Right-arm bowler':'pace','Left-arm medium':'pace',
'Left-arm fast':'pace','\xa0Left-arm fast':'pace','\xa0Right-arm fast-medium':'pace',
'Right-arm medium fast':'pace','\xa0Right-arm medium-fast':'pace',
'\xa0Right-arm offbreak':'spin','\xa0Legbreak':'spin'})
Pace=player_match[(player_match.Bowling_skill=='pace')&(player_match.is_manofThematch==1)]
Spin=player_match[(player_match.Bowling_skill=='spin')&(player_match.is_manofThematch==1)]
print("Pace Bowling Man of the Match:",len(Pace))
print("Spin Bowling Man of the Match:",len(Spin))

Ans-3:
player_match['Batting_hand'] = player_match['Batting_hand'].map({'Right-hand bat':'Right-handed',
'\xa0Right-hand bat':'Right-handed',
'Left-hand bat' : 'Left-handed',
'\xa0Left-hand bat' : 'Left-handed'})
right=player_match[(player_match.Batting_hand=='Right-handed')&(player_match.is_manofThematch==1)]['Player_Name'].value_counts()
left=player_match[(player_match.Batting_hand=='Left-handed')&(player_match.is_manofThematch==1)]['Player_Name'].value_counts()
player_match['Bowling_skill']=player_match['Bowling_skill'].map({
'Right-arm offbreak':'spin','Right-arm medium':'pace',
'Right-arm fast-medium':'pace','Left-arm fast-medium':'pace','Legbreak googly':'spin',
'Right-arm medium-fast':'pace',
'Slow left-arm orthodox':'spin','Right-arm fast':'pace',
'Slow left-arm chinaman':'spin','Left-arm medium-fast':'pace',
'Legbreak':'Spin','Right-arm bowler':'pace','Left-arm medium':'pace',
'Left-arm fast':'pace','\xa0Left-arm fast':'pace','\xa0Right-arm fast-medium':'pace',
'Right-arm medium fast':'pace','\xa0Right-arm medium-fast':'pace',
'\xa0Right-arm offbreak':'spin','\xa0Legbreak':'spin'})
spin=player_match[(player_match.Bowling_skill=='spin')&(player_match.is_manofThematch==1)]['Player_Name'].value_counts()
pace=player_match[(player_match.Bowling_skill=='pace')&(player_match.is_manofThematch==1)]['Player_Name'].value_counts()
wktkeeper=player_match[((player_match.Role_Desc=='Keeper')|(player_match.Role_Desc=='CaptainKeeper'))&(player_match.is_manofThematch==1)]['Player_Name'].value_counts()
allr=player_match[(player_match.Bowling_skill!='N/A')&(player_match.is_manofThematch==1)]['Player_Name'].value_counts()
print("the team is")
print(right[:2])
print(left[:2])
print(wktkeeper[:1])
print(allr[:1])
print(pace[:3])
print(spin[:2])

Ans-4:
max=0
for team in player_match.Player_team.unique():
for team1 in player_match.Player_team.unique():
series=player_match[(player_match.Player_team==team)&(player_match.Opposit_Team==team1)&(player_match.IsPlayers_Team_won==1)]['Match_Id'].value_counts()
if(max<len(series)):
pteam=team
oteam=team1
max=len(series)
print("the team which won maximum no. of matches is",pteam,"against",oteam)