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

Submitted Pandas Assignment #100

Open
wants to merge 1 commit 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@

# coding: utf-8

# In[1]:


import pandas as pd
import numpy as np


# In[2]:


player_match=pd.read_csv("/home/prateek/Documents/Python/Data_science/Data_science_smp/Ipl/DIM_PLAYER_MATCH.csv",encoding="ISO-8859-1",skiprows=[1])


# In[3]:


player_match


# In[4]:


#Q1:
for i in range(2008,2018):
yp=player_match.loc[(player_match.Age_As_on_match<25) & (player_match.Season_year==i)]
lyp=len(yp)
l=len(player_match)
per=(lyp/l)*100
team=yp.Player_team.value_counts().index[0]
print("% of young players and team having max players in {:d} season={:f} and {}".format(i,per,team))
yp=player_match.loc[(player_match.Age_As_on_match<25) & (player_match.is_manofThematch==1.0)]
lyp=len(yp)
l=len(player_match)
per=(lyp/l)*100
print("Percentage of man of the match award won by young player={}".format(per))


# In[11]:


#Q2:
def bowl(s):
if(s=="Legbreak" or s=="Legbreak googly"):
s="right-handed leg spin bowler"
return s
player_match.Bowling_skill=player_match.Bowling_skill.map(bowl,na_action="ignore")

def null(srs):
if(pd.isnull(srs.Bowling_skill)==True):
srs.Bowling_skill=srs.Batting_hand
return srs
player_match=player_match.apply(null,axis="columns")
right=len(player_match.loc[player_match.Bowling_skill.str.contains("right",case=False) & player_match.is_manofThematch==1])
left=len(player_match.loc[player_match.Bowling_skill.str.contains("left",case=False) & player_match.is_manofThematch==1])
print("Number of times man of the match recieved by right handed player={} , and left handed player={}".format(right,left))


# In[8]:


#Q3:
right_list=list((player_match.loc[player_match.Batting_hand.str.contains("right",case=False) & player_match.is_manofThematch==1]).Player_Name.value_counts().index[0:2])

left_list=list((player_match.loc[player_match.Batting_hand.str.contains("left",case=False) & player_match.is_manofThematch==1]).Player_Name.value_counts().index[0:2])

keeper=((player_match.loc[((player_match.Role_Desc=="Keeper") | (player_match.Role_Desc=="CaptainKeeper")) & player_match.is_manofThematch==1]).Player_Name.value_counts().index[0])


pacers=list(player_match.loc[((player_match.Bowling_skill.str.contains("fast")) | (player_match.Bowling_skill.str.contains("medium"))) & player_match.is_manofThematch==1].Player_Name.value_counts().index[10:13])

A_rounder=(player_match.loc[((player_match.Bowling_skill.str.contains("fast")) | (player_match.Bowling_skill.str.contains("medium"))) & player_match.is_manofThematch==1].Player_Name.value_counts().index[8])

spin=list(player_match.loc[((player_match.Bowling_skill.str.contains("break")) | (player_match.Bowling_skill.str.contains("slow")) | (player_match.Bowling_skill.str.contains("spin")) ) & player_match.is_manofThematch==1].Player_Name.value_counts().index[[7,12]])
#player_match.Bowling_skill.unique()

type(right_list)
team=right_list+left_list+pacers+spin
#right_list.append(keeper)
team.append(keeper)
team.append(A_rounder)
print("best team is:",team)


# In[10]:


#Q4:
match=pd.read_excel("/home/prateek/Documents/Python/Data_science/Data_science_smp/Ipl/DIM_MATCH.xlsx",encoding="ISO-8859-1")
match.dropna(axis="index",subset=["match_winner"],inplace=True)
match

def win_lose(d):
if(d.match_winner!=d.Team1):
d.match_winner=d.match_winner+"-"+d.Team1
else:
d.match_winner=d.match_winner+"-"+d.Team2
return d
(match.apply(win_lose,axis="columns")).match_winner.value_counts().index[0]

21 changes: 21 additions & 0 deletions Introduction-to-Data-Science/Week-4/Prateek/Assignment4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
1)
it use to append a binary file

2)
all file that are opened are loaded into a buffer , it helps in efficient handling and if some error occures in handling orignal file remains safe

3)
try:
import phones.call
except ImportError :
print("Some Error Ocurred while Imorting")
d={1:'a',2:'b'}
try:
print(d[3])
except KeyError:
print("Erroe:Key Not Found")

4)
file1=open("sample.txt","r+")
for line in reversed(list(file1)):
print(line,end="")
71 changes: 71 additions & 0 deletions Introduction-to-Data-Science/Week-4/Prateek/Assignment5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
1)
A class is group of different data types and funtions that share a common property

2)
Variable of Class is instance(object)

3)
Using instance we acess public members of class

4)
class classname:
#class members

5)
A method is a piece of code that is called by name that is associated with an object

6)
self heps to distuinguish different objects of same class

7)
__init__ method creates and initialize object of class

8)
using inheritance we donot need to write a method again for child class that already exist in parent class and avoid code duplication

9)
import random
class card():
suit={"Hearts":['A',2,3,4,5,6,7,8,9,10,'J','Q','K'],"Diamoond":['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_cards(card):
def shuffled(self):
if(len(card().suit["Hearts"])+len(card().suit["Diamoond"])+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_name):
print("dealt card is ", card_name," of ",card_suit)
card().suit[card_suit].remove(card_name)
#Sample Input:
"""b=card()
a=deck_of_cards()
a.shuffled()
a.deal("Hearts",'A')
print(b.suit)"""

10)
class person:
def __init__(self,first_name,last_name,phone_number,*email):
self.first_name=first_name
self.last_name=last_name
self.phone_number=phone_number
self.email=email
class address_book(person):
book=[]
def __init__(self,details):
self.add_contact(details)
def add_contact(self,details):
self.book.append(details)
def lookup_contact(self,last_name,first_name="None"):
for i in self.book:
if(first_name=="None"):
if(i.last_name==last_name):
print(i.first_name,i.last_name,i.phone_number,i.email)
else:
if(i.last_name==last_name and i.first_name==first_name):
print(i.first_name,i.last_name,i.phone_number,i.email)
#Sample Input:
#a=person("Prateek","Sahu",9753612488,["[email protected]","[email protected]"])
#address_book(a)
#c=person("anukul","Sahu",9753612488,["[email protected]","[email protected]"])
#address_book(c).lookup_contact("Sahu","anukul")