diff --git a/Introduction-to-Data-Science/Week-3/Animesh_Kumar/Assignment_4.txt b/Introduction-to-Data-Science/Week-3/Animesh_Kumar/Assignment_4.txt new file mode 100644 index 0000000..ceacb3c --- /dev/null +++ b/Introduction-to-Data-Science/Week-3/Animesh_Kumar/Assignment_4.txt @@ -0,0 +1,57 @@ +1. Classes provide a means of bundling data and functionality together. Creating a new class creates a new type of object, allowing new instances of that type to be made. Each class instance can have attributes attached to it for maintaining its state. Class instances can also have methods (defined by its class) for modifying its state. +2. It is an object that has all of the attributes (methods and members) described in the class definition. When it's created a special method is invoked (called __init__) that performs object set up (and might also invoke the parent class set up). The newly created instance has its own place in memory, and through that reference you may invoke instance methods (methods that look like def foo(self, ...)) and access (or update) members (e.g., my_object.some_member). +3. A class defines the properties and behavior for the objects represented by the abstraction.A class thus denotes a category of objects and act as a blueprint for creating such objects. An object exhibits the property and behaviors defined by its class. +4. class ClassName: + + . + . + . + +5. A method is a function that takes a class instance as its first parameter. +6. self represents the instance of the class. By using the "self" keyword we can access the attributes and methods of the class in python. __init__ is a special method in Python classes, it is the constructor method for a class. +7. "__init__" is a reseved method in python classes. It is known as a constructor in object oriented concepts. This method called when an object is created from the class and it allow the class to initialize the attributes of a class. +8. Inheritance allows the method and attributes to be shared among various classes. These are inherited from the superclassby the subclass. +Thus the same code can be used nultiple times. Hence inheritance prevents code duplication. +9. import random +import itertools +class card(): + suits=["Hearts","Spades","Clubs","Diamonds"] + ranks=["A","2","3","4","5","6","7","8","9","10","J","Q","K"] + deck = list(' '.join(card) for card in itertools.product(suits, ranks)) +class deck_of_card(card): + def shuffle1(self): + if len(card().deck)!=52: + print("Insuitable deck") + else: + for n in card().deck: + k=n.split(" ") + if (k[0] in["Heart","Spades","Clubs","Diamonds"] and k[1] in ["A","2","3","4","5","6","7","8","9","10","J","Q","K"])==False: + print("Insuitable deck") + break + else: + print("Deck is fine") + random.shuffle(card().deck) + def deal(self): + print(card().deck[0]) + del card().deck[0] +10.class person: + def __init__(self,f_name,l_name,phone_no,*email): + self.FirstName=f_name + self.LastName=l_name + self.PhoneNo=phone_no + self.email=email +class address_book(person): + add_book=[] + def __init__(self,info): + self.add_contact(info) + def add_contact(self,info): + self.add_book.append(info) + def lookup_contact(self,l_name,f_name="none"): + for i in self.add_book: + if(f_name=="none"): + if(i.LastName==l_name): + print(i.FirstName,i.LastName,i.PhoneNo,i.email) + else: + if(i.LastName==l_name and i.FirstName==f_name): + print(i.FirstName,i.LastName,i.PhoneNo,i.email) + diff --git a/Week5/Animesh_Kumar/empty_file.txt b/Week5/Animesh_Kumar/empty_file.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/Week5/Animesh_Kumar/empty_file.txt @@ -0,0 +1 @@ + diff --git a/Week5/Animesh_Kumar/week5.py b/Week5/Animesh_Kumar/week5.py new file mode 100644 index 0000000..8230ffa --- /dev/null +++ b/Week5/Animesh_Kumar/week5.py @@ -0,0 +1,98 @@ +import numpy as np +import pandas as pd + +player_match = pd.read_csv("DIM_PLAYER_MATCH.csv",delimiter=',',encoding = "ISO-8859-1", skiprows=[1]) +player_match +players=pd.read_csv("DIM_PLAYER.csv",delimiter=',',encoding = "ISO-8859-1", skiprows=[1]) + +player_match.fillna('None',inplace=True) +player_match['Player_team'].replace('sunrisers Hyderabad','Sunrisers Hyderabad',inplace=True) +player_match['Player_team'].replace('kings XI Punjab','Kings XI Punjab',inplace=True) + + + +#Q1 + +seasons=player_match['Season_year'].unique() +for i in seasons: + print("Season:",i) + young_player=player_match[(player_match.Age_As_on_match<25)&(player_match.Season_year== i)]['Player_Id'].unique() + total_players=player_match[player_match.Season_year==i]['Player_Id'].unique() + per_young_player=len(young_player)/len(total_players)*100 + print("Percentage of young player",per_young_player) + team_young=player_match.loc[player_match['Player_Id'].isin(young_player)].drop_duplicates(subset='Player_Id') + bla=team_young['Player_team'].value_counts().index[0] + print("Team Having Maximum Young Players:",bla,"\n") +mofm=player_match[(player_match.Age_As_on_match<25)&(player_match.is_manofThematch==1)]['Player_Id'].unique() +total_mofm=player_match[(player_match.is_manofThematch==1)]['Player_Id'].unique() +print("Percentage of Man of the Match won by Young Players:",len(mofm)/len(total_mofm)*100) + + + + +#Q2 + +if len(player_match['Batting_hand'].value_counts()==5) : + 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'}) +print(player_match['Batting_hand'].value_counts()) +r_won=player_match[(player_match.Batting_hand=='Right-handed')&(player_match.IsPlayers_Team_won==1)] +l_won=player_match[(player_match.Batting_hand=='Left-handed')&(player_match.IsPlayers_Team_won==1)] +r_mom=player_match[(player_match.Batting_hand=='Right-handed')&(player_match.is_manofThematch==1)] +l_mom=player_match[(player_match.Batting_hand=='Left-handed')&(player_match.is_manofThematch==1)] +print("Team won when right handed played:",len(r_won)) +print("Team won when left handed played:",len(l_won)) +print("Right handed Man of the Match:",len(r_mom)) +print("Left handed Man of the Match:",len(l_mom)) + +if len(player_match['Bowling_skill'].value_counts()==21): + player_match['Bowling_skill']=player_match['Bowling_skill'].map({ 'Right-arm offbreak':'Spin','Right-arm medium':'pace', + 'Right-arm fast-medium':'pace','Legbreak googly':'pace', + 'Right-arm medium-fast':'pace','Left-arm fast-medium':'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' +}) +print(player_match["Bowling_skill"].value_counts()) +p_won=player_match[(player_match.Bowling_skill=='pace')&(player_match.IsPlayers_Team_won==1)] +s_won=player_match[(player_match.Bowling_skill=='spin')&(player_match.IsPlayers_Team_won==1)] +p_mom=player_match[(player_match.Bowling_skill=='pace')&(player_match.is_manofThematch==1)] +s_mom=player_match[(player_match.Bowling_skill=='spin')&(player_match.is_manofThematch==1)] +print("Team won when pace bowled:",len(p_won)) +print("Team won when spin bowled:",len(s_won)) +print("Pace Bowling Man of the Match:",len(p_mom)) +print("Spin Bowling Man of the Match:",len(s_mom)) + +#Q3 + + def best_team(): + print("Best team:\n") + print(player_match[(player_match.Batting_hand=='Right-handed')&(player_match.is_manofThematch ==1)]['Player_Name'][:2]) + print(player_match[(player_match.Batting_hand=='Left-handed')&(player_match.is_manofThematch ==1)]['Player_Name'][:2]) + print(player_match[(player_match.Role_Desc=='Keeper')&(player_match.is_manofThematch ==1)]['Player_Name'][:1]) + print(player_match[(player_match.Batting_hand!='NaN')&(player_match.Bowling_skill!='NaN')&(player_match.is_manofThematch ==1)]['Player_Name'][4:5]) + print(player_match[(player_match.Bowling_skill=='pace')&(player_match.is_manofThematch==1)]['Player_Name'][5:8]) + print(player_match[(player_match.Bowling_skill=='Spin')&(player_match.is_manofThematch==1)]['Player_Name'][1:3]) +best_team() + +#Q4 + +seasons=player_match['Season_year'].unique() +for k in range(len(seasons)): + team_name=player_match[(player_match.Season_year==seasons[k])]['Player_team'].unique() + count=player_match[(player_match.Player_team==team_name[0])&(player_match.Opposit_Team==team_name[1])&(player_match.IsPlayers_Team_won==1)]['Match_Id'].value_counts() + for i in range(len(team_name)): + for j in range(len(team_name)): + s=player_match[(player_match.Player_team==team_name[i])&(player_match.Opposit_Team==team_name[j])&(player_match.IsPlayers_Team_won==1)]['Match_Id'].value_counts() + if(len(count)