# Benford’s law meets IPL, Intl. T20 and ODI cricket

“To grasp how different a million is from a billion, think about it like this: A million seconds is a little under two weeks; a billion seconds is about thirty-two years.”

“One of the pleasures of looking at the world through mathematical eyes is that you can see certain patterns that would otherwise be hidden.”

``               Steven Strogatz, Prof at Cornell University``

## Introduction

Within the last two weeks, I was introduced to Benford’s Law by 2 of my friends. Initially, I looked it up and Google and was quite intrigued by the law. Subsequently another friends asked me to check the ‘Digits’ episode, from the “Connected” series on Netflix by Latif Nasser, which I strongly recommend you watch.

Benford’s Law also called the Newcomb–Benford law, the law of anomalous numbers, or the First Digit Law states that, when dealing with quantities obtained from Nature, the frequency of appearance of each digit in the first significant place is logarithmic. For example, in sets that obey the law, the number 1 appears as the leading significant digit about 30.1% of the time, the number 2 about 17.6%, number 3 about 12.5% all the way to the number 9 at 4.6%. This interesting logarithmic pattern is observed in most natural datasets from population densities, river lengths, heights of skyscrapers, tax returns etc. What is really curious about this law, is that when we measure the lengths of rivers, the law holds perfectly regardless of the units used to measure. So the length of the rivers would obey the law whether we measure in meters, feet, miles etc. There is something almost mystical about this law.

The law has also been used widely to detect financial fraud, manipulations in tax statements, bots in twitter, fake accounts in social networks, image manipulation etc. In this age of deep fakes, the ability to detect fake images will assume paramount importance. While deviations from Benford Law do not always signify fraud, to large extent they point to an aberration. Prof Nigrini, of Cape Town used this law to identify financial discrepancies in Enron’s financial statement resulting in the infamous scandal. Also the 2009 Iranian election was found to be fradulent as the first digit percentages did not conform to those specified by Benford’s Law.

While it cannot be said with absolute certainty, marked deviations from Benford’s law could possibly indicate that there has been manipulation of natural processes. Possibly Benford’s law could be used to detect large scale match-fixing in cricket tournaments. However, we cannot look at this in isolation and the other statistical and forensic methods may be required to determine if there is fraud. Here is an interesting paper Promises and perils of Benford’s law

A set of numbers is said to satisfy Benford’s law if the leading digit d (d ∈ {1, …, 9}) occurs with probability

$P(d)=log_{10}(1+1/d)$

This law also works for number in other bases, in base b >=2

$P(d)=log_{b}(1+1/d)$

Interestingly, this law also applies to sports on the number of point scored in basketball etc. I was curious to see if this applied to cricket. Previously, using my R package yorkr, I had already converted all T20 data and ODI data from Cricsheet which is available at yorkrData2020, I wanted to check if Benford’s Law worked on the runs scored, or deliveries faced by batsmen at team level or at a tournament level (IPL, Intl. T20 or ODI).

Thankfully, R has a package benford.analysis to check for data behaviour in accordance to Benford’s Law, and I have used this package in my post

This post is also available in RPubs as Benford’s Law meets IPL, Intl. T20 and ODI

``````library(data.table)
library(reshape2)``````
``library(dplyr)``
``````library(benford.analysis)
library(yorkr)``````

In this post, I have randomly check data with Benford’s law. The fully converted dataset is available in yorkrData2020 which I have included above. You can try on any dataset including ODI (men,women),Intl T20(men,women),IPL,BBL,PSL,NTB and WBB.

## 1. Check the runs distribution by Royal Challengers Bangalore

We can see the behaviour is as expected with Benford’s law, with minor deviations

``````load("/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ipl/iplBattingBowlingDetails/Royal Challengers Bangalore-BattingDetails.RData")
rcbRunsTrends = benford(battingDetails\$runs, number.of.digits = 1, discrete = T, sign = "positive")
rcbRunsTrends``````
``````##
## Benford object:
##
## Data: battingDetails\$runs
## Number of observations used = 1205
## Number of obs. for second order = 99
## First digits analysed = 1
##
## Mantissa:
##
##    Statistic  Value
##         Mean  0.458
##          Var  0.091
##  Ex.Kurtosis -1.213
##     Skewness -0.025
##
##
## The 5 largest deviations:
##
##   digits absolute.diff
## 1      1         14.26
## 2      7         13.88
## 3      9          8.14
## 4      6          5.33
## 5      4          4.78
##
## Stats:
##
##  Pearson's Chi-squared test
##
## data:  battingDetails\$runs
## X-squared = 5.2091, df = 8, p-value = 0.735
##
##
##  Mantissa Arc Test
##
## data:  battingDetails\$runs
## L2 = 0.0022852, df = 2, p-value = 0.06369
##
## Mean Absolute Deviation (MAD): 0.004941381
## MAD Conformity - Nigrini (2012): Close conformity
## Distortion Factor: -18.8725
##
## Remember: Real data will never conform perfectly to Benford's Law. You should not focus on p-values!``````

## 2. Check the ‘balls played’ distribution by Royal Challengers Bangalore

``````load("/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ipl/iplBattingBowlingDetails/Royal Challengers Bangalore-BattingDetails.RData")
rcbBallsPlayedTrends = benford(battingDetails\$ballsPlayed, number.of.digits = 1, discrete = T, sign = "positive")
plot(rcbBallsPlayedTrends)``````

## 3. Check the runs distribution by Chennai Super Kings

The trend seems to deviate from the expected behavior to some extent in the number of digits for 5 & 7.

``````load("/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ipl/iplBattingBowlingDetails/Chennai Super Kings-BattingDetails.RData")
cskRunsTrends = benford(battingDetails\$runs, number.of.digits = 1, discrete = T, sign = "positive")
cskRunsTrends``````
``````##
## Benford object:
##
## Data: battingDetails\$runs
## Number of observations used = 1054
## Number of obs. for second order = 94
## First digits analysed = 1
##
## Mantissa:
##
##    Statistic  Value
##         Mean  0.466
##          Var  0.081
##  Ex.Kurtosis -1.100
##     Skewness -0.054
##
##
## The 5 largest deviations:
##
##   digits absolute.diff
## 1      5         27.54
## 2      2         18.40
## 3      1         17.29
## 4      9         14.23
## 5      7         14.12
##
## Stats:
##
##  Pearson's Chi-squared test
##
## data:  battingDetails\$runs
## X-squared = 22.862, df = 8, p-value = 0.003545
##
##
##  Mantissa Arc Test
##
## data:  battingDetails\$runs
## L2 = 0.002376, df = 2, p-value = 0.08173
##
## Mean Absolute Deviation (MAD): 0.01309597
## MAD Conformity - Nigrini (2012): Marginally acceptable conformity
## Distortion Factor: -17.90664
##
## Remember: Real data will never conform perfectly to Benford's Law. You should not focus on p-values!``````

## 4. Check runs distribution in all of Indian Premier League (IPL)

``````battingDF <- NULL
teams <-c("Chennai Super Kings","Deccan Chargers","Delhi Daredevils",
"Kings XI Punjab", 'Kochi Tuskers Kerala',"Kolkata Knight Riders",
"Mumbai Indians", "Pune Warriors","Rajasthan Royals",
"Rising Pune Supergiants")

setwd("/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ipl/iplBattingBowlingDetails")
for(team in teams){
battingDetails <- NULL
val <- paste(team,"-BattingDetails.RData",sep="")
print(val)
error = function(e) {
print("No data1")
setNext=TRUE
}

)
details <- battingDetails
battingDF <- rbind(battingDF,details)
}``````
``````## [1] "Chennai Super Kings-BattingDetails.RData"
## [1] "Deccan Chargers-BattingDetails.RData"
## [1] "Delhi Daredevils-BattingDetails.RData"
## [1] "Kings XI Punjab-BattingDetails.RData"
## [1] "Kochi Tuskers Kerala-BattingDetails.RData"
## [1] "Kolkata Knight Riders-BattingDetails.RData"
## [1] "Mumbai Indians-BattingDetails.RData"
## [1] "Pune Warriors-BattingDetails.RData"
## [1] "Rajasthan Royals-BattingDetails.RData"
## [1] "Royal Challengers Bangalore-BattingDetails.RData"
## [1] "Gujarat Lions-BattingDetails.RData"
## [1] "Rising Pune Supergiants-BattingDetails.RData"``````
``````trends = benford(battingDF\$runs, number.of.digits = 1, discrete = T, sign = "positive")
trends``````
``````##
## Benford object:
##
## Data: battingDF\$runs
## Number of observations used = 10129
## Number of obs. for second order = 123
## First digits analysed = 1
##
## Mantissa:
##
##    Statistic   Value
##         Mean  0.4521
##          Var  0.0856
##  Ex.Kurtosis -1.1570
##     Skewness -0.0033
##
##
## The 5 largest deviations:
##
##   digits absolute.diff
## 1      2        159.37
## 2      9        121.48
## 3      7         93.40
## 4      8         83.12
## 5      1         61.87
##
## Stats:
##
##  Pearson's Chi-squared test
##
## data:  battingDF\$runs
## X-squared = 78.166, df = 8, p-value = 1.143e-13
##
##
##  Mantissa Arc Test
##
## data:  battingDF\$runs
## L2 = 5.8237e-05, df = 2, p-value = 0.5544
##
## Mean Absolute Deviation (MAD): 0.006627966
## MAD Conformity - Nigrini (2012): Acceptable conformity
## Distortion Factor: -20.90333
##
## Remember: Real data will never conform perfectly to Benford's Law. You should not focus on p-values!``````

## 5. Check Benford’s law in India matches

``````setwd("/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/t20/t20BattingBowlingDetails")

indiaTrends = benford(battingDetails\$runs, number.of.digits = 1, discrete = T, sign = "positive")
plot(indiaTrends)``````

## 6. Check Benford’s law in all of Intl. T20

``````setwd("/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/t20/t20BattingBowlingDetails")
teams <-c("Australia","India","Pakistan","West Indies", 'Sri Lanka',
"Bermuda","Kenya","Hong Kong","Nepal","Oman","Papua New Guinea",
"United Arab Emirates","Namibia","Cayman Islands","Singapore",
"United States of America","Bhutan","Maldives","Botswana","Nigeria",
"Denmark","Germany","Jersey","Norway","Qatar","Malaysia","Vanuatu",
"Thailand")

for(team in teams){
battingDetails <- NULL
val <- paste(team,"-BattingDetails.RData",sep="")
print(val)
error = function(e) {
print("No data1")
setNext=TRUE
}

)
details <- battingDetails
battingDF <- rbind(battingDF,details)

}
``````intlT20Trends = benford(battingDF\$runs, number.of.digits = 1, discrete = T, sign = "positive")
intlT20Trends``````
``````##
## Benford object:
##
## Data: battingDF\$runs
## Number of observations used = 21833
## Number of obs. for second order = 131
## First digits analysed = 1
##
## Mantissa:
##
##    Statistic  Value
##         Mean  0.447
##          Var  0.085
##  Ex.Kurtosis -1.158
##     Skewness  0.018
##
##
## The 5 largest deviations:
##
##   digits absolute.diff
## 1      2        361.40
## 2      9        276.02
## 3      1        264.61
## 4      7        210.14
## 5      8        198.81
##
## Stats:
##
##  Pearson's Chi-squared test
##
## data:  battingDF\$runs
## X-squared = 202.29, df = 8, p-value < 2.2e-16
##
##
##  Mantissa Arc Test
##
## data:  battingDF\$runs
## L2 = 5.3983e-06, df = 2, p-value = 0.8888
##
## Mean Absolute Deviation (MAD): 0.007821098
## MAD Conformity - Nigrini (2012): Acceptable conformity
## Distortion Factor: -24.11086
##
## Remember: Real data will never conform perfectly to Benford's Law. You should not focus on p-values!``````

## Conclusion

Maths rules our lives, more than we are aware, more that we like to admit. It is there in all of nature. Whether it is the recursive patterns of Mandelbrot sets, the intrinsic notion of beauty through the golden ratio, the murmuration of swallows, the synchronous blinking of fireflies or in the almost univerality of Benford’s law on natural datasets, mathematics govern us.

Isn’t it strange that while we humans pride ourselves of freewill, the runs scored by batsmen in particular formats conform to Benford’s rule for the first digits. It almost looks like, the runs that will be scored is almost to extent predetermined to fall within specified ranges obeying Benford’s law. So much for choice.

Something to be pondered over!

Also see

# Introducing GooglyPlusPlus!!!

“We can lift ourselves out of ignorance, we can find ourselves as creatures of excellence and intelligence and skill.”
“Heaven is not a place, and it is not a time. Heaven is being perfect.”
“Your whole body, from wingtip to wingtip, is nothing more than your thought itself, in a form you can see. Break the chains of your thought, and you break the chains of your body, too.”

From Jonathan Livingstone Seagull, by Richard Bach

## Introduction

The metamorphosis is complete, from eggs to the butterfly! My R package yorkr, went on to become Googly,  and then to GooglyPlus and  now finally GooglyPlusPlus. My latest R Shiny app now provides interactive visualisation of almost all data in Cricsheet. GooglyPlusPlus visualizes the following matches

1. ODI (men)
2. ODI (women)
3. Intl. T20 (men)
4. Intl T20 (women)
5. IPL (Indian Premier League)
6. BBL (Big Bash League)
7. NTB (Natwest T20)
8. PSL (Pakistan Super League)
9. WBBL – Women’s BBL

GooglyPlusPlus is entirely based on my R package yorkr. To know more about yorkr see ‘Revitalizing R package yorkr‘ and the roughly 25+ posts on yorkr in Index of posts

This Shiny app was quite involved, and it took a lot of work to keep things organised and separate for the different forms of cricket. Anyway it is done and I am happy with the outcome.

Before you use the app, I would suggest that you take a look at the video “How to use GooglyPlusPlus?“. In this video, I show the different features of GooglyPlusPlus and how to navigate through them.

Check out GooglyPlusPlus Shiny at GooglyPlusPlus

You can clone/fork and play around with the code of GooglyPlusPlus here at Github

## A. Highlights of GooglyPlusPlus.

The R Shiny app GooglyPlusPlus has the following main pages for the 9 different cricket formats. See below

Important note: Below I will be including some random output from the GooglyPlusPlus app for different match formats, however there is a lot more features in GooglyPlusPlus

## Conclusion

There you have it. I have randomly shown  2 functions for each cricket format. There are many functions in each tab for the for the different match formats – namely IPL, BBL, Intl T20 (men,women), PSL etc.  Go ahead and give GooglyPlusPlus a spin!

To try out GooglyPlusPlus click GooglyPlusPlus. Don’t forget to check out the video How to use GooglyPlusPlus?

You can clone/fork the code from Github at GooglyPlusPlus

Hope you have fun with GooglyPlusPlus!!

You may also like

To see all posts click Index of posts

# Big Data 7: yorkr waltzes with Apache NiFi

In this post, I construct an end-to-end Apache NiFi pipeline with my R package yorkr. This post is a mirror of my earlier post Big Data-5: kNiFing through cricket data with yorkpy based on my Python package yorkpy. The  Apache NiFi Data Pipeilne  flows all the way from the source, where the data is obtained, all the way  to target analytics output. Apache NiFi was created to automate the flow of data between systems.  NiFi dataflows enable the automated and managed flow of information between systems. This post automates the flow of data from Cricsheet, from where the zip file it is downloaded, unpacked, processed, transformed and finally T20 players are ranked.

This post uses the functions of my R package yorkr to rank IPL players. This is a example flow, of a typical Big Data pipeline where the data is ingested from many diverse source systems, transformed and then finally insights are generated. While I execute this NiFi example with my R package yorkr, in a typical Big Data pipeline where the data is huge, of the order of 100s of GB, we would be using the Hadoop ecosystem with Hive, HDFS Spark and so on. Since the data is taken from Cricsheet, which are few Megabytes, this approach would suffice. However if we hypothetically assume that there are several batches of cricket data that are being uploaded to the source, of different cricket matches happening all over the world, and the historical data exceeds several GBs, then we could use a similar Apache NiFi pattern to process the data and generate insights. If the data is was large and distributed across the Hadoop cluster , then we would need to use SparkR or SparklyR to process the data.

This is shown below pictorially

While this post displays the ranks of IPL batsmen, it is possible to create a cool dashboard using UI/UX technologies like AngularJS/ReactJS.  Take a look at my post Big Data 6: The T20 Dance of Apache NiFi and yorkpy where I create a simple dashboard of multiple analytics

My R package yorkr can handle both men’s and women’s ODI, and all formats of T20 in Cricsheet namely Intl. T20 (men’s, women’s), IPL, BBL, Natwest T20, PSL, Women’s BBL etc. To know more details about yorkr see Revitalizing R package yorkr

The code can be forked from Github at yorkrWithApacheNiFi

You can take a look at the live demo of the NiFi pipeline at yorkr waltzes with Apache NiFi

Basic Flow

## 1. Overall flow

The overall NiFi flow contains 2 Process Groups a) DownloadAnd Unpack. b) Convert and Rank IPL batsmen. While it appears that the Process Groups are disconnected, they are not. The first process group downloads the T20 zip file, unpacks the. zip file and saves the YAML files in a specific folder. The second process group monitors this folder and starts processing as soon the YAML files are available. It processes the YAML converting it into dataframes before storing it as CSV file. The next  processor then does the actual ranking of the batsmen before writing the output into IPLrank.txt

This process group is shown below

#### 1.1.1 GetT20Data

The \${T20data} variable points to the specific T20 format that needs to be downloaded. I have set this to https://cricsheet.org/downloads/ipl.zip. This could be set any other data set. In fact we could have parallel data flows for different T20/ Sports data sets and generate

#### 1.1.2 SaveUnpackedData

This processor stores the YAML files in a predetermined folder, so that the data can be picked up  by the 2nd Process Group for processing

### 1.2 ProcessAndRankT20Players Process Group

This is the second process group which converts the YAML files to pandas dataframes before storing them as. CSV files. The RankIPLPlayers will then read all the CSV files, stack them and then proceed to rank the IPL players. The Process Group is shown below

#### 1.2.1 ListFile and FetchFile Processors

The left 2 Processors ListFile and FetchFile get all the YAML files from the folder and pass it to the next processor

#### 1.2.2 convertYaml2DataFrame Processor

The convertYaml2DataFrame Processor uses the ExecuteStreamCommand which call Rscript. The Rscript invoked the yorkr function convertYaml2DataframeT20() as shown below

I also use a 16 concurrent tasks to convert 16 different flowfiles at once

```library(yorkr)
args<-commandArgs(TRUE)
convertYaml2RDataframeT20(args[1], args[2], args[3])
```

#### 1.2.3 MergeContent Processor

This processor’s only job is to trigger the rankIPLPlayers when all the FlowFiles have merged into 1 file.

#### 1.2.4 RankT20Players

This processor is an ExecuteStreamCommand Processor that executes a Rscript which invokes a yorrkr function rankIPLT20Batsmen()

```library(yorkr)
args<-commandArgs(TRUE)

rankIPLBatsmen(args[1],args[2],args[3])
```

#### 1.2.5 OutputRankofT20Player Processor

This processor writes the generated rank to an output file.

### 1.3 Final Ranking of IPL T20 players

The Nodejs based web server picks up this file and displays on the web page the final ranks (the code is based on a good youtube for reading from file)

```[1] "Chennai Super Kings"
[1] "Deccan Chargers"
[1] "Delhi Daredevils"
[1] "Kings XI Punjab"
[1] "Kochi Tuskers Kerala"
[1] "Kolkata Knight Riders"
[1] "Mumbai Indians"
[1] "Pune Warriors"
[1] "Rajasthan Royals"
[1] "Royal Challengers Bangalore"
[1] "Gujarat Lions"
[1] "Rising Pune Supergiants"
[1] "Chennai Super Kings-BattingDetails.RData"
[1] "Deccan Chargers-BattingDetails.RData"
[1] "Delhi Daredevils-BattingDetails.RData"
[1] "Kings XI Punjab-BattingDetails.RData"
[1] "Kochi Tuskers Kerala-BattingDetails.RData"
[1] "Kolkata Knight Riders-BattingDetails.RData"
[1] "Mumbai Indians-BattingDetails.RData"
[1] "Pune Warriors-BattingDetails.RData"
[1] "Rajasthan Royals-BattingDetails.RData"
[1] "Royal Challengers Bangalore-BattingDetails.RData"
[1] "Gujarat Lions-BattingDetails.RData"
[1] "Rising Pune Supergiants-BattingDetails.RData"
# A tibble: 429 x 4
batsman     matches meanRuns meanSR
<chr>         <int>    <dbl>  <dbl>
1 DA Warner       130     37.9   128.
2 LMP Simmons      29     37.2   106.
3 CH Gayle        125     36.2   134.
4 HM Amla          16     36.1   108.
5 ML Hayden        30     35.9   129.
6 SE Marsh         67     35.9   120.
7 RR Pant          39     35.3   135.
8 MEK Hussey       59     33.8   105.
9 KL Rahul         59     33.5   128.
10 MN van Wyk        5     33.4   112.
# â€¦ with 419 more rows```

## Conclusion

This post demonstrated an end-to-end pipeline with Apache NiFi and R package yorkr. You can this pipeline and generated different analytics using the various functions of yorkr and display them on a dashboard.

Hope you enjoyed with post!

To see posts click Index of posts

# It’s a wrap! yorkr wraps up BBL, NTB, PSL and WBB!!!

“Do not take life too seriously. You will never get out of it alive.” – Elbert Hubbard

“How many people here have telekenetic powers? Raise my hand.” – Emo Philips

Have you ever noticed that anybody driving slower than you is an idiot, and anyone going faster than you is a maniac?” – George Carlin

It’s a wrap!!! In my previous posts,Revitalizing yorkr, I showed how you can use yorkr functions for Intl. ODI, Intl. T20 and IPL. My next post yorkr rocks women’s ODI and women’s Intl T20 yorkr handled women’s ODI and Intl. T20. In this post, yorkr wraps the remaining T20 formats namely

1. Big Bash League (BBL)
2. Natwest Super T20 (NTB)
3. Pakistan Super League (PSL)
4. Women’s Big Bash League (WBB)

The data for all the above T20 formats are taken from Cricsheet.

-All the data has been converted and is available in Github at yorkrData2020 organized as below. You can use any of the 90+ yorkr functions on the converted data.

-This post has been published at RPubs at yorkrWrapUpT20formats

• For ODI Matches men’s and women’ use
1. ODI-Part1, 2. ODI-Part2,3. ODI-Part3, 4.ODI-Part 4
• For any of the T20s formats you can use the following posts
1. T20-Part1, 2. T20-Part2, 3. T20-Part3, 4. T20-Part4

or you can use these templates Intl. T20, or similar to IPL T20

I am going to randomly pick 2 yorkr functions for each of the T20 formats BBL, NTB, PSL and WBB to demonstrate yorkr below, however you can use any of the 90+ yorkr functions

``````install.packages("../../../yorkrgit/yorkr_0.0.9.tar.gz",repos = NULL, type="source")
library(yorkr)
library(dplyr)``````

Note: In the following T20 formats I have randomly picked 2 of the 90+ yorkr functions

## A. Big Bash League (BBL)

### A1.Batting Scorecard

``````load("../../../yorkrData2020/bbl/bblMatches/Adelaide Strikers-Brisbane Heat-2017-12-31.RData")
as_bh <- overs
``## Total= 139``
``````## # A tibble: 9 x 5
##   batsman      ballsPlayed fours sixes  runs
##   <chr>              <int> <dbl> <dbl> <dbl>
## 1 AT Carey               6     0     0     2
## 2 CA Ingram             21     2     0    23
## 3 J Weatherald          14     2     1    20
## 4 JS Lehmann            17     3     0    22
## 5 JW Wells              13     1     0    12
## 6 MG Neser              25     3     2    40
## 7 PM Siddle              1     0     0     1
## 8 Rashid Khan            2     0     1     6
## 9 TM Head               17     0     0    13``````

### A2.Batting Partnership

``````load("../../../yorkrData2020/bbl/bblMatches2Teams/Melbourne Renegades-Sydney Sixers-allMatches.RData")
mr_ss_matches <- matches
m <-teamBatsmenPartnershiOppnAllMatches(mr_ss_matches,'Sydney Sixers',report="summary")
m``````
``````## # A tibble: 28 x 2
##    batsman      totalRuns
##    <chr>            <dbl>
##  1 MC Henriques       277
##  2 JR Philippe        186
##  4 MJ Lumb            165
##  5 DP Hughes          158
##  6 JC Silk            141
##  7 SPD Smith          116
##  8 JM Vince            97
##  9 TK Curran           68
## 10 J Botha             33
## # … with 18 more rows``````

## B. Natwest Super League

### B1.Team Match Partnership

``````load("../../../yorkrData2020/ntb/ntbMatches/Derbyshire-Nottinghamshire-2019-07-26.RData")
db_nt <-overs
teamBatsmenPartnershipMatch(db_nt,"Derbyshire","Nottinghamshire")``````

### B2.Batsmen vs Bowlers

``````load("../../../yorkrData2020/ntb/ntbMatches2Teams/Birmingham Bears-Leicestershire-allMatches.RData")
bb_le_matches <- matches
teamBatsmenVsBowlersOppnAllMatches(bb_le_matches,"Birmingham Bears","Leicestershire",top=3)``````

## C. Pakistan Super League (PSL)

### C1.Individual performance of Babar Azam

``````library(grid)
library(gridExtra)

babar <- getBatsmanDetails(team="Karachi Kings",name="Babar Azam",dir="../../../yorkrData2020/psl/pslBattingBowlingDetails/")``````
``## [1] "../../../yorkrData2020/psl/pslBattingBowlingDetails//Karachi Kings-BattingDetails.RData"``
``print(dim(babar))``
``## [1] 40 15``
``````p1 <-batsmanRunsVsStrikeRate(babar,"Babar Azam")
p2 <-batsmanMovingAverage(babar,"Babar Azam")
p3 <- batsmanCumulativeAverageRuns(babar,"Babar Azam")
grid.arrange(p1,p2,p3, ncol=2)``````

### C2.Bowling performance against all oppositions

``````load("../../../yorkrData2020/psl/pslMatches2Teams/Lahore Qalandars-Multan Sultans-allMatches.RData")
lq_ms_matches <- matches
teamBowlingPerfOppnAllMatches(lq_ms_matches,"Lahore Qalanders","Multan Sultans")``````
``````## # A tibble: 40 x 5
##    bowler              overs maidens  runs wickets
##    <chr>               <int>   <int> <dbl>   <dbl>
##  1 Shaheen Shah Afridi    11       1   134      11
##  2 Junaid Khan             5       0   154       8
##  3 Imran Tahir             5       0    74       6
##  4 Mohammad Ilyas          5       0    93       4
##  5 Haris Rauf              7       0   154       3
##  6 D Wiese                 7       0    92       3
##  7 Mohammad Irfan          5       0    91       3
##  8 S Lamichhane            5       0    74       3
##  9 SP Narine               8       0    48       3
## 10 MM Ali                  3       0    30       3
## # … with 30 more rows``````

## D. Women Big Bash League

### D1.Bowling scorecard

``````load("../../../yorkrData2020/wbb/wbbMatches/Hobart Hurricanes-Brisbane Heat-2018-12-30.RData")
hh_bh_match <- overs
teamBowlingScorecardMatch(hh_bh_match,'Brisbane Heat')``````
``````## # A tibble: 6 x 5
##   bowler      overs maidens  runs wickets
##   <chr>       <int>   <int> <dbl>   <dbl>
## 1 DM Kimmince     3       0    31       2
## 2 GM Harris       4       0    23       3
## 3 H Birkett       1       0     7       0
## 4 JL Barsby       3       0    21       0
## 5 JL Jonassen     4       0    33       0
## 6 SJ Johnson      4       0    17       0``````

### D2.Team batsmen partnerships

``````load("../../../yorkrData2020/wbb/wbbAllMatchesAllTeams/allMatchesAllOpposition-Perth Scorchers.RData")
ps_matches <- matches
teamBatsmenPartnershipAllOppnAllMatchesPlot(ps_matches,"Perth Scorchers",main="Perth Scorchers")``````

As mentioned above, I have randomly picked 2 yorkr functions for each of the T20 formats. You can use any of the 90+ functions for analysis of matches, teams, batsmen and bowlers.

## 1a. Ranking Big Bash League (BBL) batsman

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/bbl/bblMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/bbl/bblBattingBowlingDetails"
rankBBLBatsmen(dir=dir,odir=odir,minMatches=30)``````
``````## # A tibble: 62 x 4
##    batsman      matches meanRuns meanSR
##    <chr>          <int>    <dbl>  <dbl>
##  1 DJM Short         44     41.6   126.
##  2 SE Marsh          48     39.1   120.
##  3 AJ Finch          60     36.0   130.
##  4 AT Carey          36     35.9   129.
##  5 KP Pietersen      31     33.5   118.
##  6 UT Khawaja        40     31.5   112.
##  7 BJ Hodge          38     31.5   127.
##  8 CA Lynn           72     31.3   128.
##  9 MP Stoinis        53     30.7   112.
## 10 TM Head           45     30     131.
## # … with 52 more rows``````

## 1b. Ranking Big Bash League (BBL) bowlers

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/bbl/bblMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/bbl/bblBattingBowlingDetails"
rankBBLBowlers(dir=dir,odir=odir,minMatches=25)``````
``````## # A tibble: 53 x 4
##    bowler         matches totalWickets meanER
##    <chr>            <int>        <dbl>  <dbl>
##  1 SA Abbott           60           90   8.42
##  2 AJ Tye              45           69   7.32
##  3 B Laughlin          48           66   7.96
##  4 BCJ Cutting         71           63   8.87
##  5 BJ Dwarshuis        54           62   7.87
##  6 MG Neser            54           57   8.36
##  7 Rashid Khan         40           55   6.32
##  8 JP Behrendorff      41           53   6.55
##  9 SNJ O'Keefe         53           52   6.76
## 10 A Zampa             42           51   7.34
## # … with 43 more rows``````

## 2a. Ranking Natwest T20 League (NTB) batsman

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ntb/ntbMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ntb/ntbBattingBowlingDetails"

rankNTBBatsmen(dir=dir,odir=odir,minMatches=20)``````
``````## # A tibble: 42 x 4
##    batsman          matches meanRuns meanSR
##    <chr>              <int>    <dbl>  <dbl>
##  1 SR Hain               24     34.6   107.
##  2 M Klinger             26     34.1   118.
##  3 MH Wessels            26     33.9   122.
##  4 DJ Bell-Drummond      21     33.1   112.
##  5 DJ Malan              26     33     129.
##  6 T Kohler-Cadmore      23     33.0   118.
##  7 A Lyth                22     31.4   150.
##  8 JJ Cobb               26     30.7   110.
##  9 CA Ingram             25     30.5   153.
## 10 IA Cockbain           26     29.8   121.
## # … with 32 more rows``````

## 2b. Ranking Natwest T20 League (NTB) bowlers

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ntb/ntbMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ntb/ntbBattingBowlingDetails"

rankNTBBowlers(dir=dir,odir=odir,minMatches=20)``````
``````## # A tibble: 23 x 4
##    bowler          matches totalWickets meanER
##    <chr>             <int>        <dbl>  <dbl>
##  1 HF Gurney            23           45   8.63
##  2 AJ Tye               26           40   7.81
##  3 TS Roland-Jones      26           37   8.10
##  4 BAC Howell           20           35   6.89
##  5 TT Bresnan           21           31   8.82
##  6 MJJ Critchley        25           31   7.33
##  7 LA Dawson            24           30   6.80
##  8 TK Curran            23           28   8.19
##  9 NA Sowter            25           28   8.09
## 10 MTC Waller           25           27   7.59
## # … with 13 more rows``````

## 3a. Ranking Pakistan Super League (PSL) batsman

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/psl/pslMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/psl/pslBattingBowlingDetails"

rankPSLBatsmen(dir=dir,odir=odir,minMatches=15)``````
``````## # A tibble: 47 x 4
##    batsman      matches meanRuns meanSR
##    <chr>          <int>    <dbl>  <dbl>
##  1 Babar Azam        40     33.7   102.
##  2 L Ronchi          31     32.9   143.
##  3 DR Smith          24     30.8   111.
##  4 JJ Roy            15     30.6   123.
##  5 Kamran Akmal      46     30.1   112.
##  6 SR Watson         40     29.2   126.
##  7 Shoaib Malik      35     28.1   113.
##  8 Fakhar Zaman      38     27.6   119.
##  9 Imam-ul-Haq       15     27.4   115.
## 10 RR Rossouw        36     27.0   130.
## # … with 37 more rows``````

## 3b. Ranking Pakistan Super League (PSL) bowlers

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/psl/pslMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/psl/pslBattingBowlingDetails"

rankPSLBowlers(dir=dir,odir=odir,minMatches=15)``````
``````## # A tibble: 25 x 4
##    bowler              matches totalWickets meanER
##    <chr>                 <int>        <dbl>  <dbl>
##  1 Wahab Riaz               44           70   6.94
##  2 Hasan Ali                41           61   7.43
##  3 Faheem Ashraf            30           50   7.84
##  4 Mohammad Amir            38           48   7.16
##  5 Usman Shinwari           26           43   8.64
##  6 Mohammad Sami            29           40   7.60
##  7 Shadab Khan              40           38   7.57
##  8 Shaheen Shah Afridi      24           34   7.88
##  9 Rumman Raees             24           33   7.77
## 10 Mohammad Hasnain         16           28   8.65
## # … with 15 more rows``````

## 4a. Ranking Women’s Big Bash League (WBB) batsman

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/wbb/wbbMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/wbb/wbbBattingBowlingDetails"
rankWBBBatsmen(dir=dir,odir=odir,minMatches=15)``````
``````## # A tibble: 36 x 4
##    batsman    matches meanRuns meanSR
##    <chr>        <int>    <dbl>  <dbl>
##  1 BL Mooney       27     46.7  129.
##  2 SFM Devine      22     43.5  111.
##  3 EA Perry        16     41.1   97.1
##  4 MM Lanning      19     38     98.2
##  5 JE Cameron      22     32.9  127.
##  6 DN Wyatt        24     32    112.
##  7 AE Jones        17     28.9  107.
##  8 AJ Healy        19     28.4  122.
##  9 M du Preez      19     27    101.
## 10 L Lee           18     26.9   98.9
## # … with 26 more rows``````

## 4b. Ranking Women’s Big Bash League (WBB) bowlers

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/wbb/wbbMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/wbb/wbbBattingBowlingDetails"
rankWBBBowlers(dir=dir,odir=odir,minMatches=15)``````
``````## # A tibble: 31 x 4
##    bowler      matches totalWickets meanER
##    <chr>         <int>        <dbl>  <dbl>
##  1 M Strano         23           37   7.25
##  2 DM Kimmince      24           36   7.46
##  3 SJ Coyte         22           29   7.59
##  4 JL Jonassen      24           28   6.81
##  5 SJ Johnson       24           27   6.61
##  6 ML Schutt        22           26   6.03
##  7 SFM Devine       22           24   7.58
##  8 M Brown          23           23   7.33
##  9 M Kapp           19           23   5.05
## 10 H Graham         19           22   7.68
## # … with 21 more rows``````

## Conclusion

yorkr can handle ODI and T20 matches in the format as represented in Cricsheet. In my posts, I have shown how yorkr can be used for Intl. ODI and Intl. T20 for both men and women. yorkr can also handle all T20 formats like IPL T20, BBL, Natwest T20, PSL and women’s BBL. Go ahead take yorkr for a ride and check out your favorite teams and players.

Hope you have fun!!!

You may also like

To see all posts click Index of Posts

# yorkr rocks women’s One Day International (ODI) and International T20!!

“Life is not measured by the number of breaths we take, but by the moments that take our breath away.” Maya Angelou

“Life shrinks or expands in proportion to one’s courage.” Anais Nin

“Devotion to the truth is the hallmark of morality; there is no greater, nobler, more heroic form of devotion than the act of a man who assumes the responsibility of thinking.” Ayn Rand in Atlas Shrugged

# Introduction

yorkr, this time, rocks women’s cricket!!! In this post, my R package yorkr analyzes women’s One Day International and International T20. The latest changes in my R package yorkr, as mentioned in my last post Revitalizing R package yorkr, included the modifications for the segregation men’s and women’s ODI and T20 matches into separate folders while converting them from YAML to R data frames. As the data was already converted I could just use the yorkr functions 90+ to analyze the women’s ODI and women’s T20. The data for this is taken from Cricsheet

My R package yorkr has 4 classes of functions

## ODI Functions

• Class 1: Analysis of ODI matches – See ODI-Part 1
• Class 2: Analysis of all ODI matches between 2 ODI teams – See ODI Part 2
• Class 3 : Analysis of all matches played by a ODI team againsta all other ODI teams – See ODI Part 3
• Class 4 : Analysis of ODI batsmen and bowlers – See ODI Part 4

Note
-The converted data is available at yorkrData
-This RMarkdown file has been published at RPubs at yorkrAnalyzesWomensODIT20

``install.packages("../../../yorkrgit/yorkr_0.0.9.tar.gz",repos = NULL, type="source")``

## 1. Analysis of women’s ODI matches

``library(yorkr)``

### Save all matches between 2 teams

``#saveAllMatchesBetweenTeams("../../../yorkrData2020/odi/odiWomenMatches/","../../../yorkrData2020/odi/odiWomenMatches2Teams/")``

### Save all matches played by an ODI team against all other ODI teams

``#saveAllMatchesAllOpposition("../../../yorkrData2020/odi/odiWomenMatches/","../../../yorkrData2020/odi/odiWomenAllMatchesAllTeams/")``

Since there are several functions in each class, I have randomly selected a few functions to demonstrate yorkr’s analysis ## ODI Match Analysis (Class 1) In the functions below ODI women matches are analyzed as in the India-Australia ODI in 7 Feb 2016.

#### 1.Scorecard

``````load("../../../yorkrData2020/odi/odiWomenMatches/Australia-India-2016-02-07.RData")
aus_ind <- overs
teamBattingScorecardMatch(aus_ind,'India')``````
``## Total= 223``
``````## # A tibble: 7 x 5
##   batsman         ballsPlayed fours sixes  runs
##   <chr>                 <int> <int> <dbl> <dbl>
## 1 H Kaur                   42     2     0    22
## 2 J Goswami                 4     1     0     4
## 3 M Raj                   113    12     0    89
## 4 PG Raut                  31     2     0    24
## 5 S Mandhana               52     7     0    55
## 6 S Pandey                 18     2     0    17
## 7 V Krishnamurthy          21     2     0    12``````

#### 2.Batting Partnerships

The partnerships in this match between India and Australia. Mithali Raj tops the list, with partnerships with Smriti Mandhana, Harmanpreet Kaur and Punam Raut. The next highest partnership is Smriti Mandhana

``teamBatsmenPartnershipMatch(aus_ind,"India","Australia")``

## Analyze bowling in the women’s ODI England-New Zealand match on 15 Feb 2013

#### 3.Wicket kind

``````load("../../../yorkrData2020/odi/odiWomenMatches/England-New Zealand-2013-02-15.RData")
eng_nz <- overs
teamBowlingWicketKindMatch(eng_nz,"England","New Zealand")``````

#### 4.Match worm graph

Plot the match worm graph for Pakistan-South Africa women’s ODI 25 Jun 2017

``````load("../../../yorkrData2020/odi/odiWomenMatches/Pakistan-South Africa-2017-06-25.RData")
pak_sa <-overs
matchWormGraph(pak_sa,'Pakistan',"South Africa")``````

## Analysis of team in all matches against another team (Class 2)

#### 5. Team Batsmen partnerships

The functions below analyze all matches between South Africa and Sri Lanka.

``````load("../../../yorkrData2020/odi/odiWomenMatches2Teams/South Africa-Sri Lanka-allMatches.RData")
sa_sl_matches <- matches
m <-teamBatsmenPartnershiOppnAllMatches(sa_sl_matches,'South Africa',report="summary")
m``````
``````## # A tibble: 16 x 2
##    batsman        totalRuns
##    <chr>              <dbl>
##  1 M du Preez           241
##  2 M Kapp               194
##  3 L Wolvaardt          168
##  4 D van Niekerk        138
##  5 L Lee                138
##  6 T Chetty             136
##  7 A Steyn              118
##  8 L Goodall             89
##  9 S Luus                71
## 10 N de Klerk            35
## 11 CL Tryon              15
## 12 F Tunnicliffe         15
## 13 S Ismail               9
## 14 M Klaas                2
## 15 Y Fourie               1
## 16 B Bezuidenhout         0``````
``````teamBatsmenPartnershipOppnAllMatchesChart(sa_sl_matches,"Sri Lanka","South Africa")
``````

#### 6. Team bowler wicketkind

The plot below gives the performance if women Indian ODI bowlers in all ODI matches against England. The top wicket takers are Jhulan Goswami, Ekta Bisht, Gouher Sultana

``````load("../../../yorkrData2020/odi/odiWomenMatches2Teams/India-England-allMatches.RData")
ind_eng_matches <- matches
teamBowlersWicketsOppnAllMatches(ind_eng_matches,"India","England")``````

## Performance of women ODI teams against all other teams in all matches (Class 3)

#### 7. Overall batting scorecard

West Indies top scorers in ODI in all matches. The top scorers in West Indies are 1. Stafanie Taylor 2. Deandra Dottin 3. Hayley Matthews

``````load("../../../yorkrData2020/odi/odiWomenAllMatchesAllteams/allMatchesAllOpposition-West Indies.RData")
wi_matches <- matches
m <-teamBattingScorecardAllOppnAllMatches(wi_matches,theTeam="West Indies")``````
``## Total= 4629``
``m``
``````## # A tibble: 31 x 5
##    batsman          ballsPlayed fours sixes  runs
##    <chr>                  <int> <int> <int> <dbl>
##  1 SR Taylor               1087    83     7   766
##  2 DJS Dottin               778    69    21   641
##  3 HK Matthews              734    71     4   527
##  4 SA Campbelle             649    39     4   396
##  5 Kycia A Knight           517    35     2   284
##  6 CN Nation                554    31     1   274
##  7 Kyshona A Knight         578    35    NA   264
##  8 MR Aguilleira            481    20     3   252
##  9 B Cooper                 289    19     3   176
## 10 NY McLean                230    18     2   155
## # … with 21 more rows``````

## Individual batsman and bowler performances (Class 4)

#### 8. Batsmen performances

The functions below perform individual batsman and bowler analysis. I chose the top women ODI batsman

1. Mithali Raj (Ind) has the highest ODI runs with a career average of 50.64
2. Charlotte Edwards (Eng)
3. Suzie Bates (NX)
``````#india_details <- getTeamBattingDetails("India",dir="../../../yorkrData2020/odi/odiWomenMatches", save=TRUE,odir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")
#eng_details <- getTeamBattingDetails("England",dir="../../../yorkrData2020/odi/odiWomenMatches", save=TRUE,odir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")
#nz_details <- getTeamBattingDetails("New Zealand",dir="../../../yorkrData2020/odi/odiWomenMatches", save=TRUE,odir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")

mithali <- getBatsmanDetails(team="India",name="M Raj",dir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")``````
``## [1] "../../../yorkrData2020/odi/odiWomenBattingBowlingDetails/India-BattingDetails.RData"``
``charlotte <- getBatsmanDetails(team="England",name="CM Edwards",dir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")``
``## [1] "../../../yorkrData2020/odi/odiWomenBattingBowlingDetails/England-BattingDetails.RData"``
``suzie<- getBatsmanDetails(team="New Zealand",name="SW Bates",dir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")``
``## [1] "../../../yorkrData2020/odi/odiWomenBattingBowlingDetails/New Zealand-BattingDetails.RData"``

## Plot Runs vs Strike Rate

``````library(grid)
library(gridExtra)
p1 <-batsmanRunsVsStrikeRate(mithali,"Mithali Raj")
p2 <- batsmanRunsVsStrikeRate(charlotte, "Charlotte E")
p3 <- batsmanRunsVsStrikeRate(suzie, "Suzie Bates")
grid.arrange(p1,p2,p3, ncol=2)``````

## Plot the moving average

``````p1 <-batsmanMovingAverage(mithali,"Mithali Raj")
p2 <- batsmanMovingAverage(charlotte, "Charlotte E")
p3 <- batsmanMovingAverage(suzie, "Suzie Bates")
grid.arrange(p1,p2,p3, ncol=2)``````

``````p1 <-batsmanCumulativeAverageRuns(mithali,"Mithali Raj")
p2 <- batsmanCumulativeAverageRuns(charlotte, "Charlotte E")
p3 <- batsmanCumulativeAverageRuns(suzie, "Suzie Bates")
grid.arrange(p1,p2,p3, ncol=2)``````

## Analyze ODI bowler performances

#### 9. Bowler performances

The following 3 bowlers have been chosen for analysis

1. Jhulan Goswami (Ind) is the highest overwall wicket taker with 225 wicket
2. Anisa Mohammed (WI)
3. Sana Mir (Pak)
``````#india_details <- getTeamBowlingDetails("India",dir="../../../yorkrData2020/odi/odiWomenMatches", save=TRUE,odir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")
#wi_details <- getTeamBowlingDetails("West Indies",dir="../../../yorkrData2020/odi/odiWomenMatches", save=TRUE,odir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")
#pak_details <- getTeamBowlingDetails("Pakistan",dir="../../../yorkrData2020/odi/odiWomenMatches", save=TRUE,odir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")

jhulan <- getBowlerWicketDetails(team="India",name="J Goswami",dir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")
anisa <- getBowlerWicketDetails(team="West Indies",name="A Mohammed",dir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")
sana <- getBowlerWicketDetails(team="Pakistan",name="Sana Mir",dir="../../../yorkrData2020/odi/odiWomenBattingBowlingDetails")``````

Plot the bowler Mean Economy Rate

``````p1<-bowlerMeanEconomyRate(jhulan,"Jhulan G")
p2<-bowlerMeanEconomyRate(anisa, "Anisa M")
p3<-bowlerMeanEconomyRate(sana, "Sana Mir")
grid.arrange(p1,p2,p3, ncol=2)``````

Plot the cumulative average wickets taken by the bowlers

``````p1<-bowlerCumulativeAvgWickets(jhulan,"Jhulan G")
p2<-bowlerCumulativeAvgWickets(anisa, "Anisa M")
p3<-bowlerCumulativeAvgWickets(sana, "Sana Mir")
grid.arrange(p1,p2,p3, ncol=2)``````

# 2. Analysis of women’s International Twenty 20 matches

I have chosen some random yorkr functions to show the analysis of T20 players and matches

## T20 Functions

There are the following class of T20 functions

• Class 1: Analysis of T20 matches – See T20-Part 1
• Class 2: Analysis of all T20 matches between 2 T20 teams – See T20 Part 2
• Class 3 : Analysis of all matches played by a T20 team againsta All other T20 teams – See T20 Part 3
• Class 4 : Analysis of T20 batsmen and bowlers – See T20 Part 4

You can also refer to the yorkr template that I created Analysis of International T20 matches with yorkr templates

### Save all matches between teams

``#saveAllMatchesBetweenTeams("../../../yorkrData2020/t20/t20WomenMatches/","../../../yorkrData2020/t20/t20WomenMatches2Teams/")``

### Save all T20 matches played by a team against all other teams

``#saveAllMatchesAllOpposition("../../../yorkrData2020/t20/t20WomenMatches/","../../../yorkrData2020/t20/t20WomenAllMatchesAllTeams/")``

## T20 Match Analysis (Class 1)

#### 10. Batting scorecard

Print the scorecard for the Bangladesh- Ireland match played on 3 Apr 2014

``````load("../../../yorkrData2020/t20/t20WomenMatches/Bangladesh-Ireland-2014-04-03.RData")
ban_ire <- overs
``## Total= 95``
``````## # A tibble: 9 x 5
##   batsman         ballsPlayed fours sixes  runs
##   <chr>                 <int> <dbl> <dbl> <dbl>
## 1 Ayasha Rahman            19     2     0    12
## 2 Fahima Khatun             2     0     0     0
## 3 Lata Mondal              12     1     0     8
## 4 Panna Ghosh               3     0     0     4
## 5 Rumana Ahmed             14     3     0    16
## 6 Salma Khatun              6     1     0     7
## 7 Shaila Sharmin            7     0     0     6
## 8 Shamima Sultana          11     0     0     7
## 9 Sharmin Akhter           46     3     0    35``````

Plot the performance of T20 batsmen against in bowlers in Germany – Netherlands.

``````load("../../../yorkrData2020/t20/t20WomenMatches/Germany-Netherlands-2019-06-27.RData")
ger_net <- overs
teamBatsmenVsBowlersMatch(ger_net,'Netherlands',"Germany",plot=TRUE)``````

#### 11. Bowling scorecard

Print the bowling scorecard of Hong Kong-Kuwait T20 match played on 25 Feb 2019

``````load("../../../yorkrData2020/t20/t20WomenMatches/Hong Kong-Kuwait-2019-02-25.RData")
hk_kuw <-overs
teamBowlingScorecardMatch(hk_kuw,'Hong Kong')``````
``````## # A tibble: 5 x 5
##   bowler      overs maidens  runs wickets
##   <chr>       <int>   <int> <dbl>   <int>
## 1 Chan Ka Man     2       0     5       1
## 2 KY Chan         3       1     2       4
## 3 M Hill          2       0     6       1
## 4 M Wai Siu       2       0    11       1
## 5 M Yousaf        1       1     0       3``````

#### 12. Team batting partnerships

Print the partnership among Indian T20 women in all matches against England

``````load("../../../yorkrData2020/t20/t20WomenMatches2Teams/India-England-allMatches.RData")
ind_eng_matches <- matches
m <-teamBatsmenPartnershiOppnAllMatches(ind_eng_matches,'India',report="detailed")
m[1:30,]``````
``````##       batsman      nonStriker partnershipRuns totalRuns
## 1       M Raj        A Sharma               2       233
## 2       M Raj      BS Fulmali              25       233
## 3       M Raj       DB Sharma              16       233
## 4       M Raj          H Kaur              18       233
## 5       M Raj       J Goswami               6       233
## 6       M Raj         KV Jain               5       233
## 7       M Raj        L Kumari               5       233
## 8       M Raj     N Niranjana               3       233
## 9       M Raj        N Tanwar              17       233
## 10      M Raj         PG Raut              41       233
## 11      M Raj      R Malhotra               5       233
## 12      M Raj      S Mandhana              17       233
## 13      M Raj          S Naik              10       233
## 14      M Raj        S Pandey              19       233
## 15      M Raj        SK Naidu              37       233
## 16      M Raj V Krishnamurthy               7       233
## 17 S Mandhana          H Deol              20       145
## 18 S Mandhana    JI Rodrigues              47       145
## 19 S Mandhana           M Raj              32       145
## 20 S Mandhana   Shafali Verma              46       145
## 21     H Kaur        A Sharma               1       137
## 22     H Kaur        AA Patil               8       137
## 23     H Kaur       DB Sharma              14       137
## 24     H Kaur         E Bisht               3       137
## 25     H Kaur       J Goswami              11       137
## 26     H Kaur    JI Rodrigues              12       137
## 27     H Kaur           M Raj              19       137
## 28     H Kaur      MR Meshram              33       137
## 29     H Kaur        N Tanwar               2       137
## 30     H Kaur         PG Raut               0       137``````

#### 13. Team batting partnerships (plot)

Plot the batting partnership of Indian T20 womern against England

The best batsmen are Mithali Raj, Smriti Mandhana and Harmanpreet Kaur in that order

``teamBatsmenPartnershipOppnAllMatchesChart(ind_eng_matches,"India","England")``

#### 14. Team Wicketkind

Plot the wicket kind taken by the bowlers of Scotland against USA

``````load("../../../yorkrData2020/t20/t20WomenMatches2Teams/Scotland-United States of America-allMatches.RData")
sco_usa_matches <- matches
teamBowlersWicketsOppnAllMatches(sco_usa_matches,"Scotalnd","USA")``````

## Performance of teams against all other teams in all T20 matches (Class 3)

#### 15. Overall team scorecard

Print the batting scorecard of Zimbabwe against all other teams

``````load("../../../yorkrData2020/t20/t20WomenAllMatchesAllTeams/allMatchesAllOpposition-Zimbabwe.RData")
zim_matches <- matches
m <-teamBattingScorecardAllOppnAllMatches(zim_matches,theTeam="Zimbabwe")``````
``## Total= 571``
``m``
``````## # A tibble: 7 x 5
##   batsman      ballsPlayed fours sixes  runs
##   <chr>              <int> <int> <int> <dbl>
## 1 SM Mayers            181    20     3   216
## 2 M Mupachikwa         139     9    NA   125
## 3 CS Mugeri             88     9     2   119
## 4 M Musonda             38     2     1    46
## 5 J Nkomo               25     3    NA    34
## 6 A Ndiraya             14     3    NA    18
## 7 AC Mushangwe          13    NA    NA    13

``````

#### 15. Team batting partnerships

Print the batting partnership of West Indies. The best performances are by 1. Stafanie Taylor 2. Deandra Dottin 3. Hayley Matthews

``````load("../../../yorkrData2020/t20/t20WomenAllMatchesAllTeams/allMatchesAllOpposition-West Indies.RData")
wi_matches <- matches
m <- teamBatsmenPartnershipAllOppnAllMatches(wi_matches,theTeam='West Indies')
m``````
``````## # A tibble: 29 x 2
##    batsman        totalRuns
##    <chr>              <dbl>
##  1 SR Taylor           1199
##  2 DJS Dottin           912
##  3 HK Matthews          458
##  4 SA Campbelle         407
##  5 B Cooper             300
##  6 SACA King            287
##  7 MR Aguilleira        250
##  8 CN Nation            243
##  9 Kycia A Knight       240
## 10 NY McLean            142
## # … with 19 more rows``````

#### 16. Team bowling wicketkind

The plot below shows the women T20 bowlers who have performed the best against India namely 1. Katherine Brunt (Eng) 2. Elysse Perry (Aus) 3. Anya Shrubsole

``````load("../../../yorkrData2020/t20/t20WomenAllMatchesAllTeams/allMatchesAllOpposition-India.RData")
ind_matches <- matches
teamBowlingWicketKindAllOppnAllMatches(ind_matches,t1="India",t2="All")``````

## Analyze women T20 batsmen & bowlers (Class 4)

#### 17. T20 batsmen performances

The following 4 players were chosen

1. Harmanpreet Kaur (Ind)
2. Suzie Bates (NZ)
3. Meg Lanning (Aus)
4. Stafanie Tay;or (WI)
``````#india_details <- getTeamBattingDetails("India",dir="../../../yorkrData2020/t20/t20WomenMatches", save=TRUE,odir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")
#eng_details <- getTeamBattingDetails("England",dir="../../../yorkrData2020/t20/t20WomenMatches", save=TRUE,odir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")
#aus_details <- getTeamBattingDetails("Australia",dir="../../../yorkrData2020/t20/t20WomenMatches", save=TRUE,odir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")
#wi_details <-  getTeamBattingDetails("West Indies",dir="../../../yorkrData2020/t20/t20WomenMatches", save=TRUE,odir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")
#nz_details <-  getTeamBattingDetails("New Zealand",dir="../../../yorkrData2020/t20/t20WomenMatches", save=TRUE,odir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")

harmanpreet <- getBatsmanDetails(team="India",name="H Kaur",dir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")``````
``## [1] "../../../yorkrData2020/t20/t20WomenBattingBowlingDetails/India-BattingDetails.RData"``
``suzie <- getBatsmanDetails(team="New Zealand",name="SW Bates",dir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")``
``## [1] "../../../yorkrData2020/t20/t20WomenBattingBowlingDetails/New Zealand-BattingDetails.RData"``
``meg <- getBatsmanDetails(team="Australia",name="MM Lanning",dir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")``
``## [1] "../../../yorkrData2020/t20/t20WomenBattingBowlingDetails/Australia-BattingDetails.RData"``
``stafanie <- getBatsmanDetails(team="West Indies",name="SR Taylor",dir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")``
``## [1] "../../../yorkrData2020/t20/t20WomenBattingBowlingDetails/West Indies-BattingDetails.RData"``

Plot the performance of the players against opposition.

``batsmanRunsAgainstOpposition(harmanpreet,"Harmanpreet")``

``batsmanRunsAgainstOpposition(suzie,"Suzie Bates")``

``batsmanRunsAgainstOpposition(stafanie,"Stafanie Taylor")``

``batsmanRunsAgainstOpposition(meg,"Meg Lanning")``

Plot the cumulative strike rate of the players. Meg Lanning has the best strike rate of the lot. Stafanie and Suzie also touch a strike rate of 100

``````p1<-batsmanCumulativeStrikeRate(harmanpreet,"Harmanpreet")
p2<-batsmanCumulativeStrikeRate(suzie,"Suzie Bates")
p3<-batsmanCumulativeStrikeRate(stafanie,"Stafanie Taylor")
p4 <-batsmanCumulativeStrikeRate(meg,"Meg Lanning")
grid.arrange(p1,p2,p3,p4, ncol=2)``````

## Analyze women’s T20 bowlers.

#### 18. T20 bowler performances

The following bowlers were chosen for analysis

2. Anisa Mohammed (WI)
3. Ellyse Perry (Aus)
4. Anya Shrubsole (England)
``````#india_details <- getTeamBowlingDetails("India",dir="../../../yorkrData2020/t20/t20WomenMatches", save=TRUE,odir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")
#wi_details <- getTeamBowlingDetails("West Indies",dir="../../../yorkrData2020/t20/t20WomenMatches", save=TRUE,odir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")
#aus_details <- getTeamBowlingDetails("Australia",dir="../../../yorkrData2020/t20/t20WomenMatches", save=TRUE,odir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")
#eng_details <- getTeamBowlingDetails("England",dir="../../../yorkrData2020/t20/t20WomenMatches", save=TRUE,odir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")

anisa <- getBowlerWicketDetails(team="West Indies",name="A Mohammed",dir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")
ellyse <- getBowlerWicketDetails(team="Australia",name="EA Perry",dir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")
anya <- getBowlerWicketDetails(team="England",name="A Shrubsole",dir="../../../yorkrData2020/t20/t20WomenBattingBowlingDetails")``````

Plot the bowler’s moving average

``````p1<-bowlerMovingAverage(poonam,"Poonam Yadav")
p2<-bowlerMovingAverage(anisa,"Anisa M")
p3 <-bowlerMovingAverage(ellyse,"Ellyse Perry")
p4 <-bowlerMovingAverage(anya,"Anya Shrubsole")
grid.arrange(p1,p2,p3,p4, ncol=2)``````

Plot the bowlers Cumulative Average Wickets

``````p1<-bowlerCumulativeAvgWickets(poonam,"Poonam Yadav")
p2<-bowlerCumulativeAvgWickets(anisa,"Anisa M")
p3 <-bowlerCumulativeAvgWickets(ellyse,"Ellyse Perry")
p4 <-bowlerCumulativeAvgWickets(anya,"Anya Shrubsole")
grid.arrange(p1,p2,p3,p4, ncol=2)``````

## 3a. Rank women ODI batsmen

Note: Mithali Raj (Ind) tops the ODI table with the most runs and highest average in ODI. The Cricsheet data does not have the earlier years in which she played. Hence you may see a much lower average for Mithali Raj

``````library(yorkr)
dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/odi/odiWomenMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/odi/odiWomenBattingBowlingDetails"

rankODIBatsmen(dir=dir,odir=odir,minMatches=30)``````

``````## # A tibble: 24 x 4
##    batsman          matches meanRuns meanSR
##    <chr>              <int>    <dbl>  <dbl>
##  1 AE Satterthwaite      32     61.5   81.2
##  2 MM Lanning            47     49.5   85.0
##  3 TT Beaumont           35     45.8   68.5
##  4 EA Perry              42     45.7   74.3
##  5 SW Bates              42     44.0   70.9
##  6 NR Sciver             35     43.0   94.7
##  7 M Raj                 35     42.8   64.1
##  8 AC Jayangani          48     38.6   59.9
##  9 NE Bolton             32     36.5   60.5
## 10 T Chetty              34     33.1   70.3
## # … with 14 more rows``````

## 3b. Rank women ODI bowlers

Note: Jhulan Goswami tops the ODI bowlers with the most wickets. However the rank below is based on the available data in Cricsheet

``````library(yorkr)
dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/odi/odiWomenMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/odi/odiWomenBattingBowlingDetails"

rankODIBowlers(dir=dir,odir=odir,minMatches=30)``````

``````## # A tibble: 19 x 4
##    bowler        matches totalWickets meanER
##    <chr>           <int>        <dbl>  <dbl>
##  1 JL Jonassen        44           76   3.90
##  2 M Kapp             49           70   3.80
##  3 S Ismail           44           65   3.82
##  4 KH Brunt           42           62   3.57
##  5 EA Perry           43           58   4.44
##  6 A Shrubsole        41           58   4.07
##  7 J Goswami          33           58   3.59
##  8 S Luus             41           54   4.82
##  9 D van Niekerk      40           53   3.84
## 10 ML Schutt          35           48   4.46
## 11 A Khaka            33           47   4.08
## 12 JL Gunn            30           43   4.23
## 13 I Ranaweera        35           42   4.89
## 14 Sana Mir           32           41   4.29
## 15 LA Marsh           30           40   4.16
## 16 NR Sciver          36           37   4.64
## 17 NR Sciver          36           37   4.64
## 18 NR Sciver          36           37   4.64
## 19 NR Sciver          36           37   4.64``````

## 4a. Rank women T20 batsman

``````library(yorkr)
dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/t20/t20WomenMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/t20/t20WomenBattingBowlingDetails"

rankT20Batsmen(dir=dir,odir=odir,minMatches=30)``````

``````## # A tibble: 30 x 4
##    batsman       matches meanRuns meanSR
##    <chr>           <int>    <dbl>  <dbl>
##  1 SR Taylor          39     33.1   96.7
##  2 MM Lanning         53     29.3  102.
##  3 EJ Villani         32     28.2   94.8
##  4 D van Niekerk      41     27.3   88.2
##  5 SJ Taylor          46     26.7  100.
##  6 SW Bates           35     26.1   99.8
##  7 AC Jayangani       41     25.5   94.7
##  8 Bismah Maroof      52     24.5   83.0
##  9 DJS Dottin         38     24    109.
## 10 CM Edwards         44     23.7   94.1
## # … with 20 more rows``````

## 4b. Rank women T20 bowlers

``````library(yorkr)
dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/t20/t20WomenMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/t20/t20WomenBattingBowlingDetails"

rankT20Bowlers(dir=dir,odir=odir,minMatches=30)``````
``````## # A tibble: 20 x 4
##    bowler           matches totalWickets meanER
##    <chr>              <int>        <dbl>  <dbl>
##  1 A Shrubsole           50           76   5.95
##  2 Nida Dar              50           59   5.99
##  3 KH Brunt              49           57   5.93
##  4 JL Jonassen           50           55   5.31
##  5 EA Perry              51           52   5.67
##  6 S Ismail              50           52   5.40
##  7 ML Schutt             39           50   6.17
##  8 D van Niekerk         39           47   5.45
##  9 D Hazell              35           44   4.95
## 10 NR Sciver             44           43   6.30
## 11 JL Gunn               30           41   6.14
## 12 A Mohammed            43           41   5.80
## 13 M Kapp                31           39   5.08
## 14 Asmavia Iqbal         33           36   6.39
## 15 Sana Mir              46           36   5.85
## 16 HASD Siriwardene      35           33   6.31
## 17 EA Osborne            30           31   5.62
## 18 S Luus                37           29   7.13
## 19 KDU Prabodhani        33           25   4.87
## 20 Bismah Maroof         35           22   6.49``````

# Conclusion

While I have just shown how to use a small subset of functions, you can use the entire set of yorkr functions to analyze individual matches, head-2-head confrontation of two teams, performance of a teams against all other teams and finally performance of individual batsmen and bowlers in women’s ODI and T20 games.

You may also like

To see all posts click Index of posts

# Revitalizing R package yorkr

There is nothing so useless as doing efficiently that which should not be done at all. Peter Drucker

The most important thing in communication is to hear what isn’t being said. Peter Drucker

“Work expands to fill the time available for its completion.” Corollary: “Expenditure rises to meet income.” Parkinson’s law

## Introduction

“Operation successful!!!the Programmer Surgeon in me, thought to himself. What should have been a routine surgery, turned out to be a major operation in the end, which involved several grueling hours. The surgeon looked at the large chunks of programming logic in the operation tray, which had been surgically removed, as they had outlived their utility and had partly become dysfunctional. The surgeon glanced at the new, concise code logic which had replaced the earlier somewhat convoluted logic, with a smile of satisfaction,

To, those who tuned in late, I am referring to my R package yorkr which I had created in many years ago, in early 2016. The package had worked well for quite some time on data from Cricsheet. Cricsheet went into a hiatus in late 2017-2018, and came alive back in 2019. Unfortunately, a key function in the package, started to malfunction. The diagnosis was that the format of the YAML files had changed, in newer files, which resulted in the problem. I had got mails from users mentioning that yorkr was not converting the new YAML files. This was on my to do list for a long time, and a week or two back, I decided to “bite the bullet” and fix the issue. I hoped the fix would be trivial but it was anything but. Finally, I took the hard decision of re-designing the core of the yorkr package, which involved converting YAML files to RData (dataframes). Also, since it has been a while since I did R code, having done more of Python stuff in recent times, I had to jog my memory with my earlier 2 posts Essential R and R vs Python

I spent many hours, tweaking and fixing the new logic so that it worked on the older and new files. Finally, I am happy to say that the new code is much more compact and probably less error prone.

I also had to ensure that the converted files performed exactly on all the other yorkr functions. I ran all the my yorkr functions in my yorkr posts on ODI, Intl. T20 and IPL and made sure the results were identical. (Phew!!)

The changes will be available in CRAN in yorkr_0.0.8

Do take a look at my yorkr posts. All the functions work correctly. Do use help, as I have changed a few functions. I will have my posts reflect the correct usage, but some function or other may slip the cracks.

1. One Day Internationals ODI-Part1ODI-Part2ODI-Part3ODI-Part4
2. International T20s – T20-Part1,T20-Part2,T20-Part3,T20-Part4
3. Indian Premier League IPL-Part1IPL-Part2,IPL-Part3IPL-Part4

While making the changes, I also touched up some functions and made them more user friendly (added additional arguments etc). But by and large, yorkr is still yorkr and is intact.It just sports some spanking, new YAML conversion logic.

Note:

1. The code is available in Github yorkr
2. This RMarkdown has been published at RPubs Revitalizing yorkr
3. I have already converted the YAML files for ODI, Intl T20 and IPL. You can access and download the converted data from Github at yorkrData2020
``````setwd("/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrgit")
install.packages("yorkr_0.0.8.tar.gz",repos = NULL, type="source")
library(yorkr)``````

Below I rank batsmen and bowlers in ODIs, T20 and IPL based on the data from Cricsheet.

## 1a. Rank ODI Batsmen

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/odi/odiMenMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/odi/odiBattingBowlingDetails"

rankODIBatsmen(dir=dir,odir=odir,minMatches=50)``````

``````## # A tibble: 151 x 4
##    batsman        matches meanRuns meanSR
##    <chr>            <int>    <dbl>  <dbl>
##  1 Babar Azam          52     50.2   87.2
##  2 SD Hope             51     48.7   71.0
##  3 V Kohli            207     48.4   79.4
##  4 HM Amla            159     46.6   82.4
##  5 DA Warner          114     46.1   88.0
##  6 AB de Villiers     190     45.5   94.5
##  7 JE Root            108     44.9   82.5
##  8 SR Tendulkar        96     43.9   77.1
##  9 IJL Trott           63     43.1   68.9
## 10 Q de Kock          106     42.0   82.7
## # … with 141 more rows``````

## 1b. Rank ODI Bowlers

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/odi/odiMenMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/odi/odiBattingBowlingDetails"

rankODIBowlers(dir=dir,odir=odir,minMatches=30)``````
``````## # A tibble: 265 x 4
##    bowler           matches totalWickets meanER
##    <chr>              <int>        <dbl>  <dbl>
##  1 SL Malinga           191          308   5.25
##  2 MG Johnson           142          238   4.73
##  3 Shakib Al Hasan      157          214   4.72
##  4 Shahid Afridi        166          213   4.69
##  5 JM Anderson          143          207   4.96
##  6 KMDN Kulasekara      161          190   4.94
##  7 SCJ Broad            115          189   5.31
##  8 DW Steyn             114          188   4.96
##  9 Mashrafe Mortaza     139          180   4.97
## 10 Saeed Ajmal          106          180   4.17
## # … with 255 more rows``````

## 2a. Rank T20 Batsmen

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/t20/t20MenMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/t20/t20BattingBowlingDetails"

rankT20Batsmen(dir=dir,odir=odir,minMatches=50)``````
``````## # A tibble: 43 x 4
##    batsman          matches meanRuns meanSR
##    <chr>              <int>    <dbl>  <dbl>
##  1 V Kohli               61     39.0   132.
##  3 CH Gayle              50     31.1   124.
##  4 BB McCullum           69     30.7   126.
##  5 PR Stirling           66     29.6   116.
##  6 MJ Guptill            70     29.6   125.
##  7 DA Warner             75     29.1   128.
##  8 AD Hales              50     28.1   120.
##  9 TM Dilshan            78     26.7   105.
## 10 RG Sharma             72     26.4   120.
## # … with 33 more rows``````

## 2b. Rank T20 Bowlers

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/t20/t20MenMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/t20/t20BattingBowlingDetails"

rankT20Bowlers(dir=dir,odir=odir,,minMatches=30)``````

``````## # A tibble: 153 x 4
##    bowler          matches totalWickets meanER
##    <chr>             <int>        <dbl>  <dbl>
##  1 SL Malinga           78          115   7.39
##  2 Shahid Afridi        89           98   6.80
##  3 Saeed Ajmal          62           92   6.30
##  4 Umar Gul             56           87   7.40
##  5 KMDN Kulasekara      56           72   7.25
##  6 TG Southee           55           69   8.68
##  7 DJ Bravo             60           69   8.41
##  8 DW Steyn             47           69   7.00
##  9 Shakib Al Hasan      57           69   6.82
## 10 SCJ Broad            55           68   7.83
## # … with 143 more rows``````

## 3a. Rank IPL Batsmen

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ipl/iplMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ipl/iplBattingBowlingDetails"

rankIPLBatsmen(dir=dir,odir=odir,,minMatches=50)``````
``````## # A tibble: 69 x 4
##    batsman        matches meanRuns meanSR
##    <chr>            <int>    <dbl>  <dbl>
##  1 DA Warner          130     37.9   128.
##  2 CH Gayle           125     36.2   134.
##  3 SE Marsh            67     35.9   120.
##  4 MEK Hussey          59     33.8   105.
##  5 KL Rahul            59     33.5   128.
##  6 V Kohli            175     31.6   119.
##  7 AM Rahane          116     30.7   108.
##  8 AB de Villiers     141     30.3   135.
##  9 F du Plessis        65     29.4   117.
## 10 S Dhawan           140     29.0   114.
## # … with 59 more rows``````

## 3a. Rank IPL Bowlers

``````dir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ipl/iplMatches"
odir="/Users/tvganesh/backup/software/cricket-package/yorkr-cricsheet/yorkrData2020/ipl/iplBattingBowlingDetails"

rankIPLBowlers(dir=dir,odir=odir,,minMatches=30)``````
``````## # A tibble: 143 x 4
##    bowler          matches totalWickets meanER
##    <chr>             <int>        <dbl>  <dbl>
##  1 SL Malinga          120          184   6.99
##  2 SP Narine           108          137   6.71
##  3 Harbhajan Singh     131          134   7.11
##  4 DJ Bravo             85          118   8.18
##  5 B Kumar              86          116   7.43
##  6 YS Chahal            82          102   7.85
##  7 R Ashwin             92           98   6.81
##  8 JJ Bumrah            76           91   7.47
##  9 PP Chawla            85           87   8.02
## 10 RA Jadeja            89           85   7.93
## # … with 133 more rows``````

##Conclusion

Go ahead and give yorkr a spin once yorkr_0.0.8 is available in CRAN. I hope you have fun. Do get back to me if you have any issues.

I’ll be back. Watch this space!!

You may also like

To see all posts click Index of posts

# Big Data 6: The T20 Dance of Apache NiFi and yorkpy

“I don’t count my sit-ups. I only start counting once it starts hurting. ”

“Hard work beats talent when talent doesn’t work hard.”

Tim Notke

In my previous post Big Data 5: kNiFI-ing through cricket data with Apache NiFi and yorkpy, I created a Big Data Pipeline that takes raw data in YAML format from a Cricsheet to processing and ranking IPL T20 players. In that post I had mentioned that we could create a similar pipeline to create a real time dashboard of IPL Analytics. I could have have done this but I needed to know how to create a Web UI. After digging and poking around, I have been able to create a simple Web UI running off Apache Web server. This UI uses basic JQuery and CSS to display a real time IPL T20 dashboard. As in my previous post, this is an end-2-end Big Data pipeline which can handle large data sets at scheduled times, process them and generate real time dashboards.

We could imagine an inter-galactic T20 championship league where T20 data comes in every hour or sooner and we need to perform analytics to see if us earthlings are any better than people with pointy heads  or little green men. The NiFi pipeline could be used as-is, however the yorkpy package would have to be rewritten in Pyspark. That is in another eon, though.

My package yorkpy has around ~45+ functions which fall in the following main categories

1. Pitching yorkpy . short of good length to IPL – Part 1 :Class 1: This includes functions that convert the yaml data of IPL matches into Pandas dataframe which are then saved as CSV. This part can perform analysis of individual IPL matches.
2. Pitching yorkpy.on the middle and outside off-stump to IPL – Part 2 :Class 2:This part includes functions to create a large data frame for head-to-head confrontation between any 2IPL teams says CSK-MI, DD-KKR etc, which can be saved as CSV. Analysis is then performed on these team-2-team confrontations.
3. Pitching yorkpy.swinging away from the leg stump to IPL – Part 3 Class 3:The 3rd part includes the performance of any IPL team against all other IPL teams. The data can also be saved as CSV.
4. Pitching yorkpy … in the block hole – Part 4 :Class 4: This part performs analysis of individual IPL batsmen and bowlers

Watch the live demo of the end-2-end NiFi pipeline at ‘The T20 Dance

You can download the NiFi template and associated code from Github at  T20 Dance

The Apache NiFi Pipeline is shown below

## 1. T20 Dance – Overall NiFi Pipeline

There are 5 process groups

## 2. ListAndConvertYaml2DataFrames

This post starts with having the YAML files downloaded and unpacked from Cricsheet.  The individual YAML files are converted into Pandas dataframes and saved as CSV. A concurrency of 12 is used to increase performance and process YAML files in parallel. The processor MergeContent creates a merged content to signal the completion of conversion and triggers the other Process Groups through a funnel.

## 3. Analyse individual IPL T20 matches

This Process Group ‘Analyse T20 matches’  used the yorkpy’s Class 1 functions which can perform analysis of individual IPL T20 matches. The matchWorm() and matchScorecard() functions are used, through any other function could have been used. The Process Group is shown below

## 4. Analyse performance of an IPL team in all matches against another IPL team

This Process Group ‘Analyse performance of IPL team in all matched against another IPL team‘ does analysis in all matches between any 2 IPL teams (Class 2) as shown below

## 5. Analyse performance of IPL team in all matches against all other IPL teams

This uses Class 3 functions. Individual data sets for each IPL team versus all other IPL teams is created before Class 3 yorkpy functions are invoked. This is included below

## 6. Analyse performances of IPL batsmen and bowlers

This Process Group uses Class 4 yorkpy functions. The match CSV files are processed to get batting and bowling details before calling the individual functions as shown below

## 7. IPL T20 Dashboard

The IPL T20 Dashboard is shown

## Conclusion

This NiFI pipeline was done for IPL T20 however, it could be done for any T20 format like Intl T20, BBL, Natwest etc which are posted in Cricsheet. Also, only a subset of the yorkpy functions were used. There is a much wider variety of functions available.

Hope the T20 dance got your foot a-tapping!

To see all posts click Index of posts

# Ranking T20 players in Intl T20, IPL, BBL and Natwest using yorkpy

There is a voice that doesn’t use words, listen.
When someone beats a rug, the blows are not against the rug, but against the dust in it.
I lost my hat while gazing at the moon, and then I lost my mind.
Rumi

## Introduction

After a long hiatus, I am back to my big, bad, blogging ways! In this post I rank T20 players from several different leagues namely

• International T20
• Indian Premier League (IPL) T20
• Big Bash League (BBL) T20
• Natwest Blast (NTB) T20

I have added 8 new functions to my Python Package yorkpy, which will perform the ranking for the above 4 T20 League formats. To know more about my Python package see Pitching yorkpy . short of good length to IPL – Part 1, and the related posts on yorkpy. The code can be easily extended to other leagues which have a the same ‘yaml’ format for the matches. I also fixed some issues which started to crop up, possibly because a few things have changed in the new data.

The new functions are

1. rankIntlT20Batting()
2. rankIntlT20Batting()
3. rankIPLT20Batting()
4. rankIPLT20Batting
5. rankBBLT20Batting()
6. rankBBLT20Batting()
7. rankNTBT20Batting()
8. rankNTBT20Batting()

The yorkpy package uses data from Cricsheet

You can clone/fork the code for yorkpy at yorkpy

yorkpy can be installed with ‘pip install yorkpy

## 1. International T20

The steps to do before ranking for International T20 matches are 1. Download International T20 zip file from Cricsheet Intl T20 2. Unzip the file. This will create a folder with yaml files

``````import yorkpy.analytics as yka
#yka.convertAllYaml2PandasDataframesT20("../t20s","../data")``````

This above step will convert the yaml files into CSV files. Now do the ranking as below

## 1a. Ranking of International T20 batsmen

``````import yorkpy.analytics as yka
intlT20RankBatting=yka.rankIntlT20Batting("C:\\software\\cricket-package\\yorkpyPkg\\data\\data")
``````##                      matches  runs_mean     SR_mean
## batsman
## V Kohli                   58  38.672414  125.212402
## KS Williamson             42  32.595238  122.884631
## CH Gayle                  50  31.140000  111.869984
## BB McCullum               69  29.492754  117.011666
## MM Lanning                48  28.812500   98.582663
## SJ Taylor                 44  28.659091   98.684856
## MJ Guptill                68  28.573529  117.673702
## DA Warner                 71  28.507042  121.142746
## DPMD Jayawardene          53  27.584906  107.787092
## KC Sangakkara             54  26.407407  106.039838
## JP Duminy                 68  26.294118  114.606717
## TM Dilshan                78  26.243590   97.910384
## RG Sharma                 65  25.907692  113.056548
## H Masakadza               53  25.566038   99.453880``````

## 1b. Ranking of International T20 bowlers

``````import yorkpy.analytics as yka
intlT20RankBowling=yka.rankIntlT20Bowling("C:\\software\\cricket-package\\yorkpyPkg\\data\\data")``````
``intlT20RankBowling.head(15)``
``````##                       matches  wicket_mean  econrate_mean
## bowler
## Umar Gul                   58     1.603448       7.637931
## SL Malinga                 78     1.500000       7.409188
## Saeed Ajmal                63     1.492063       6.451058
## DW Steyn                   46     1.478261       7.014855
## A Shrubsole                45     1.422222       6.294444
## M Morkel                   41     1.292683       7.680894
## KMDN Kulasekara            57     1.280702       7.476608
## TG Southee                 51     1.274510       8.759804
## SCJ Broad                  53     1.264151            inf
## Shakib Al Hasan            58     1.241379       6.836207
## R Ashwin                   44     1.204545       7.162879
## Nida Dar                   44     1.204545       6.083333
## KH Brunt                   44     1.204545       5.982955
## KD Mills                   42     1.166667       8.289683
## SR Watson                  46     1.152174       8.246377``````

## 2. Indian Premier League (IPL) T20

The steps to do before ranking for IPL T20 matches are 1. Download IPL T20 zip file from Cricsheet IPL T20 2. Unzip the file. This will create a folder with yaml files

``````import yorkpy.analytics as yka
#yka.convertAllYaml2PandasDataframesT20("../ipl","../ipldata")``````

This above step will convert the yaml files into CSV files in the /ipldata folder. Now do the ranking as below

## 2a. Ranking of batsmen in IPL T20

``````import yorkpy.analytics as yka
IPLT20RankBatting=yka.rankIPLT20Batting("C:\\software\\cricket-package\\yorkpyPkg\\data\\ipldata")
``````##                    matches  runs_mean     SR_mean
## batsman
## DA Warner              129  37.589147  119.917864
## CH Gayle               123  36.723577  125.256818
## SE Marsh                70  36.314286  114.707578
## KL Rahul                59  33.542373  123.424971
## MEK Hussey              60  33.400000  100.439187
## V Kohli                174  32.413793  115.830849
## KS Williamson           42  31.690476  120.443172
## AB de Villiers         143  30.923077  128.967081
## JC Buttler              45  30.800000  132.561154
## AM Rahane              118  30.330508  102.240398
## SR Tendulkar            79  29.949367  101.651959
## F du Plessis            65  29.415385  112.462114
## Q de Kock               51  29.333333  110.973836
## SS Iyer                 47  29.170213  102.144222
## G Gambhir              155  28.741935  103.997558``````

## 2b. Ranking of bowlers in IPL T20

``````import yorkpy.analytics as yka
IPLT20RankBowling=yka.rankIPLT20Bowling("C:\\software\\cricket-package\\yorkpyPkg\\data\\ipldata")
``````##                      matches  wicket_mean  econrate_mean
## bowler
## SL Malinga               122     1.540984       7.173361
## Imran Tahir               43     1.465116       8.155039
## A Nehra                   88     1.375000       7.923295
## MJ McClenaghan            56     1.339286       8.638393
## Rashid Khan               46     1.304348       6.543478
## Sandeep Sharma            79     1.303797       7.860759
## MM Patel                  63     1.301587       7.530423
## DJ Bravo                 131     1.282443       8.458333
## M Morkel                  70     1.257143       7.760714
## SP Narine                109     1.256881       6.747706
## YS Chahal                 83     1.228916       8.103659
## R Vinay Kumar            104     1.221154       8.556090
## RP Singh                  82     1.219512       8.149390
## CH Morris                 52     1.211538       7.854167
## B Kumar                  117     1.205128       7.536325``````

## 3. Natwest T20

The steps to do before ranking for Natwest T20 matches are 1. Download Natwest T20 zip file from Cricsheet NTB T20 2. Unzip the file. This will create a folder with yaml files

``````import yorkpy.analytics as yka
#yka.convertAllYaml2PandasDataframesT20("../ntb","../ntbdata")``````

This above step will convert the yaml files into CSV files in the /ntbdata folder. Now do the ranking as below

## 3a. Ranking of NTB batsmen

``````import yorkpy.analytics as yka
NTBT20RankBatting=yka.rankNTBT20Batting("C:\\software\\cricket-package\\yorkpyPkg\\data\\ntbdata")
``````##                      matches  runs_mean     SR_mean
## batsman
## Babar Azam                13  44.461538  121.268809
## T Banton                  13  42.230769  139.376274
## JJ Roy                    12  41.250000  142.182147
## DJM Short                 12  40.250000  131.182294
## AN Petersen               12  37.916667  132.522727
## IR Bell                   13  37.615385  130.104721
## M Klinger                 26  35.346154  112.682922
## EJG Morgan                16  35.062500  129.817650
## AJ Finch                  19  34.578947  137.093465
## MH Wessels                26  33.884615  116.300969
## S Steel                   11  33.545455  140.118207
## DJ Bell-Drummond          21  33.142857  108.566309
## Ashar Zaidi               11  33.000000  178.553331
## DJ Malan                  26  33.000000  120.127202
## T Kohler-Cadmore          23  32.956522  112.493019``````

## 3b. Ranking of NTB bowlers

``````import yorkpy.analytics as yka
NTBT20RankBowling=yka.rankNTBT20Bowling("C:\\software\\cricket-package\\yorkpyPkg\\data\\ntbdata")
``````##                        matches  wicket_mean  econrate_mean
## bowler
## MW Parkinson                11     2.000000       7.628788
## HF Gurney                   23     1.956522       8.831884
## GR Napier                   12     1.916667       8.694444
## R Rampaul                   19     1.736842       7.131579
## P Coughlin                  11     1.727273       8.909091
## AJ Tye                      26     1.692308       8.227564
## GC Viljoen                  12     1.666667       7.708333
## BAC Howell                  21     1.666667       6.857143
## BW Sanderson                12     1.583333       7.902778
## KJ Abbott                   14     1.571429       9.398810
## JE Taylor                   13     1.538462       9.839744
## JDS Neesham                 12     1.500000      10.812500
## MJ Potts                    12     1.500000       8.486111
## TT Bresnan                  21     1.476190       8.817460
## T van der Gugten            13     1.461538       7.211538``````

## 4. Big Bash Leagure (BBL) T20

The steps to do before ranking for BBL T20 matches are 1. Download BBL T20 zip file from Cricsheet BBL T20 2. Unzip the file. This will create a folder with yaml files

``````import yorkpy.analytics as yka
#yka.convertAllYaml2PandasDataframesT20("../bbl","../bbldata")``````

This above step will convert the yaml files into CSV files in the /bbldata folder. Now do the ranking as below

## 4a. Ranking of BBL batsmen

``````import yorkpy.analytics as yka
BBLT20RankBatting=yka.rankBBLT20Batting("C:\\software\\cricket-package\\yorkpyPkg\\data\\bbldata")
``````##                 matches  runs_mean     SR_mean
## batsman
## DJM Short            43  40.883721  118.773047
## SE Marsh             47  39.148936  113.616053
## AJ Finch             62  36.306452  120.271231
## AT Carey             37  34.945946  120.125341
## UT Khawaja           41  31.268293  107.355655
## CA Lynn              74  31.162162  121.746578
## MS Wade              46  30.782609  120.310081
## TM Head              45  30.000000  126.769564
## MEK Hussey           23  29.173913  109.492934
## BJ Hodge             29  29.000000  124.438040
## BR Dunk              39  28.230769  106.149913
## AD Hales             31  27.161290  117.678008
## BB McCullum          34  27.058824  115.486392
## GJ Bailey            57  27.000000  121.159220
## MR Marsh             47  26.510638  114.994909``````

## 4b. Ranking of BBL bowlers

``````import yorkpy.analytics as yka
BBLT20RankBowling=yka.rankBBLT20Bowling("C:\\software\\cricket-package\\yorkpyPkg\\data\\bbldata")
``````##                    matches  wicket_mean  econrate_mean
## bowler
## Yasir Arafat            15     2.000000       7.587778
## CH Morris               15     1.733333       8.572222
## TK Curran               27     1.629630       8.716049
## TT Bresnan              13     1.615385       8.775641
## JR Hazlewood            18     1.555556       7.361111
## CJ McKay                15     1.533333       8.555556
## DR Sams                 36     1.527778       8.581019
## AC McDermott            14     1.500000       9.166667
## JP Faulkner             20     1.500000       8.345833
## SP Narine               12     1.500000       7.395833
## AJ Tye                  51     1.490196       8.101307
## M Kelly                 21     1.476190       8.908730
## SA Abbott               73     1.438356       8.737443
## B Laughlin              82     1.426829       8.332317
## SW Tait                 31     1.419355       8.895161``````

## Conclusion

You should be able to now rank players in the above formats as new data is added to Cricsheet. yorkpy can also be used for other leagues which follow the Cricsheet format.

To see all posts click Index of posts

# Analyzing T20 matches with yorkpy templates

## 1. Introduction

In this post I create yorkpy templates for end-to-end analysis of any T20 matches that are available on Cricsheet as yaml format. These templates can be used to analyze Intl. T20, IPL, BBL and Natwest T20. In fact they can be used for any T20 games which have been saved in the yaml format as specified by Cricsheet Cricheet.

Noteyorkpy is the clone of my R package yorkr see yorkr pads up for the Twenty20s: Part 1- Analyzing team”s match performance

With these templates you can convert all T20 match data which is in yaml format to Pandas dataframes and save them as CSV. Note The data for Intl T20, IPL, BBL and Natwest T20 have already been converted and are available at allYorkpyData. This templates is also available at Github at yorkpyTemplate. The template includes the following steps

1. Template for conversion and setup
2. Analysis of Any T20 match
3. Analysis of a T20 team in all matches against another T20 team
4. Analysis of a T20 team in all matches against all other teams
5. Analysis of T20 batsmen and bowlers

You can recreate the files as more matches are added to Cricsheet site in IPL 2017 and future seasons. This post contains all the steps needed for detailed analysis of IPL matches, teams and IPL player. This will also be my reference in future if I decide to analyze IPL in future!

Install yorkpy with pip install yorkpy

Data conversion of the yaml files have to be done before any analysis of T20 batsmen, bowlers, any T20 match matches between any 2 T20 team or analysis of a teams performance against all other team can be done

The first step is To convert the YAML files that are available for the different T20 leagues namely Intl. T20, IPL, BBL, Natwest T20 which are available in yaml format in Cricsheet. For initial data setup we need to use slighly different functions for each of the T20 leagues since the teams are different. The function to convert yaml to Pandas dataframe and save as CSV is common for all leagues

## A. For International T20

``````import yorkpy.analytics as yka
# COnvert yaml to pandas and save as CSV
#yka.convertAllYaml2PandasDataframesT20(".", "..\\data1")

# Save all matches between any 2 Intl T20 countries
#yka.saveAllMatchesBetween2IntlT20s(dir1)

#Save all matches between an Intl.T20 country and all other countries
#yka.saveAllMatchesAllOppositionIntlT20(dir1)

# Get batting details for a country
#yka.getTeamBattingDetails(<country>,dir=dir1, save=True)

#Get bowling details
#yka.getTeamBowlingDetails(<country>,dir=dir1, save=True)``````

## B. For Indian Premier League (IPL)

``````import yorkpy.analytics as yka
# COnvert yaml to pandas and save as CSV
#yka.convertAllYaml2PandasDataframesT20(".", "..\\data1")

# Save all matches between any 2 IPL teams
#yka.saveAllMatchesBetween2IPLTeams(dir1)

#Save all matches between an IPL team and all other teams
#yka.saveAllMatchesAllOppositionIPLT20(dir1)

# Get batting details for an IPL team
#yka.getTeamBattingDetails(<team1>,dir=dir1, save=True)

#Get bowling details for an IPL team
#yka.getTeamBowlingDetails(<team1>>,dir=dir1, save=True)``````

## C. For Big Bash League (BBL)

``````import yorkpy.analytics as yka
# COnvert yaml to pandas and save as CSV
#yka.convertAllYaml2PandasDataframesT20(".", "..\\data1")

# Save all matches between any 2 BBL teams
#yka.saveAllMatchesBetween2BBLTeams(dir1)

#Save all matches between an BBL team and all other teams
#yka.saveAllMatchesAllOppositionBBLT20(dir1)

# Get batting details for an BBL team
#yka.getTeamBattingDetails(<team1>,dir=dir1, save=True)

#Get bowling details for an BBL team
#yka.getTeamBowlingDetails(<team1>>,dir=dir1, save=True)``````

## D For Natwest T20

``````import yorkpy.analytics as yka
# COnvert yaml to pandas and save as CSV
#yka.convertAllYaml2PandasDataframesT20(".", "..\\data1")

# Save all matches between any 2 NWB teams
#yka.saveAllMatchesBetween2NWBTeams(dir1)

#Save all matches between an NWB team and all other teams
#yka.saveAllMatchesAllOppositionNWBT20(dir1)

# Get batting details for an NWB team
#yka.getTeamBattingDetails(<team1>,dir=dir1, save=True)

#Get bowling details for an NWB team
#yka.getTeamBowlingDetails(<team1>>,dir=dir1, save=True)``````

Once the conversion has been done and the data has been setup we can use any of the yorkpy functions for the the 4 leagues (Intl. T20, IPL, BBL or Natwest T20) There are four classes of functions. These functions can be used for any of the

1. Class 1 – Functions that analyze a single T20 match
2. Class 2 – Functions that analyze the performance of a T20 team in all matches against another T20 team
3. Class 3 – Functions that analyze the performance of a T20 team against all other teams
4. Class 4 – Functions that analyze individual T20 batsmen or bowler

## 2. Class 1 functions

These functions analyze a single T20 match (Intl T20, BBL, IPL or Natwest T20) To see actual usage of Class 1 function see Pitching yorkpy … short of good length to IPL – Part 1

``````import yorkpy.analytics as yka
# Get scorecard
#scorecard,extras=yka.teamBattingScorecardMatch(<team1>,"Name of Team")

#Get partnership
#yka.teamBatsmenPartnershipMatch(match,<team1>,<team2>,plot=True/False)

#Batsmen vs bowler
#yka.teamBatsmenVsBowlersMatch(match,<team1>,<team2>,plot=True/False)

#Bowling scorecard
#a=yka.teamBowlingScorecardMatch(match,<team1>)

#Wicket Kind
#yka.teamBowlingWicketKindMatch((match,<team1>,<team2>)

#Wicket Match
#yka.teamBowlingWicketMatch(match,<team1>,<team2>,plot=True/False)

#Bowler vs Batsman
#yka.teamBowlersVsBatsmenMatch(match,<team1>,<team2>)

#Match worm chart
#yka.matchWormChart(match,<team1>,<team2>,)``````

## 3. Class 2 functions

These set of functions analyze the performance a T20 team for e.g. Intl T20, BBL or Natwest T20 in all matches against another T20 team (country or IPL, BBL or Natwest T20 team. To see usages of Class 2 functions see Pitching yorkpy…on the middle and outside off-stump to IPL – Part 2

``````import yorkpy.analytics as yka

# Batting partnerships - Table
#m=yka.teamBatsmenPartnershiOppnAllMatches(team1_team2_matches,<team1/team2>,report="summary/detailed", top=<n>)

# Batting partnerships - Plot
#yka.teamBatsmenPartnershipOppnAllMatchesChart(team1_team2_matches,<team1>,<team2> plot=<True/False>, top=<N>, partnershipRuns=<M>)

#Batsmen vs Bowlers
#yka.teamBatsmenVsBowlersOppnAllMatches(team1_team2_matches,<team1>,<team2> plot=<True/False>, top=<N>,runsScored=<M>)

# Batting scorecard
#scorecard=yka.teamBattingScorecardOppnAllMatches(team1_team2_matches,<team1>,<team2>)

#Bowling scorecard
#scorecard=yka.teamBowlingScorecardOppnAllMatches(team1_team2_matches,<team1>,<team2>)

#Bowling wicket kind
#yka.teamBowlingWicketKindOppositionAllMatches(team1_team2_matches,<team1>,<team2>,plot=<True/False>,top=<N>,wickets=<M>)

#Bowler vs batsman
#yka.teamBowlersVsBatsmenOppnAllMatches(team1_team2_matches,<team1>,<team2>,plot=<True/False>,top=<N>,runsConceded=<M>)

# Wins vs losses
#yka.plotWinLossBetweenTeams(team1_team2_matches,<team1>,<team2>)

#Wins by win type
#yka.plotWinsByRunOrWickets(team1_team2_matches,<team1>)

#Wins by toss decision
#yka.plotWinsbyTossDecision(team1_team2_matches,<team1>,tossDecision=<field/bat>)
``````

## 4. Class 3 functions

This set of functions deals with analyzing the performance of a T20 team (Intl. T20, IPL, BBL or Natwest T20) in all matches against all other teams. To see usages of Class 3 functions see Pitching yorkpy…swinging away from the leg stump to IPL – Part 3. After the data is save all matches between all oppositions we can use this data

``````import yorkpy.analytics as yka
#Batsman partnerships
#m=yka.teamBatsmenPartnershiAllOppnAllMatches(allmatches,<team1>,report=<"summary"/"detailed", top=<N>,partnershipRuns=<M>)

#Batsmen vs Bowlers
#yka.teamBatsmenVsBowlersAllOppnAllMatches(allmatches,<team1>,plot=<True/False>,top=N>,runsScored=<M>)

#Batting scorecard
#scorecard=yka.teamBattingScorecardAllOppnAllMatches(allmatches,<team1>)

#Bowling scorecard
#scorecard=yka.teamBowlingScorecardAllOppnAllMatches(allmatches,<team1>)

#Bowling wicket kind
#yka.teamBowlingWicketKindAllOppnAllMatches(allmatches,<team1>,plot=<True/False>,top=<N>,wickets=<M>)

# Bowler vs Batsmen
#yka.teamBowlersVsBatsmenAllOppnAllMatches(allmatches,<team1>,plot=<True/False>,top=<N>,runsConceded=<M>)

# Wins vs losses
#yka.plotWinLossByTeamAllOpposition(allmatches,<team1>,plot=<"summary"/"detailed">)

# Wins by win type
#yka.plotWinsByRunOrWicketsAllOpposition(allmatches,<team1>)

# Wins by toss decision
#yka.plotWinsbyTossDecisionAllOpposition(allmatches,<team1>,tossDecision='bat'/'field',plot='summary'/'detailed')``````

## 5. Class 4 functions

This set of functions are used for analyzing individual batsman/bowler. From the converted xxx-BattingDetails.csv and xxx-BowlingDetails.csv we can get the batsman and bowler details as shown below. Subsequenly we can perform analyses of the individual batsman and bowler. To see actual usages of Class 4 functions see Pitching yorkpy … in the block hole – Part 4

``````import yorkpy.analytics as yka

#Batsman analyses
#Get batsman Dataframe
#batsmanDF=yka.getBatsmanDetails(<team1>,<batsman>,dir=dir1)

#Batsman Runs vs Deliveries
#yka.batsmanRunsVsDeliveries(batsmanDF,<batsmanName>)

#Batsman fours and sixes

#Batsman dismissals
#yka.batsmanDismissals(batsmanDF,<batsmanName>)

#Batsman Runs vs Strike Rate
#yka.batsmanRunsVsStrikeRate(batsmanDF,<batsmanName>)

#Batsman Moving average
#yka.batsmanMovingAverage(batsmanDF,<batsmanName>)

#Batsman Cumulative average
#yka.batsmanCumulativeAverageRuns(batsmanDF,<batsmanName>)

#Batsman Cumulative Strike rate
#yka.batsmanCumulativeStrikeRate(batsmanDF,<batsmanName>)

#Batsman Runs against opposition
#yka.batsmanRunsAgainstOpposition(batsmanDF,<batsmanName>)

#Batsman Runs against opposition
#yka.batsmanRunsVenue(batsmanDF,<batsmanName>)

#Bowler analyses
#Get bowler dataframe
#bowlerDF=yka.getBowlerWicketDetails(<team1>,<bowler>dir=dir1)

#Mean economy rate
#yka.bowlerMeanEconomyRate(bowlerDF,<bowlerName>)

#Mean Economy rate
#yka.bowlerMeanEconomyRate(bowlerDF,<bowlerName>)

#Mean Runs conceded
#yka.bowlerMeanRunsConceded(bowlerDF,<bowlerName>)

#Moving average of wickets
#yka.bowlerMovingAverage((bowlerDF,<bowlerName>)

# Cumulative average of wickets
#yka.bowlerCumulativeAvgWickets(bowlerDF,<bowlerName>)

# Cumulative economy rate
#yka.bowlerCumulativeAvgEconRate(bowlerDF,<bowlerName>)

# Wicket plot
#yka.bowlerWicketPlot(df,name)

# Wicket against opposition
#yka.bowlerWicketsAgainstOpposition(bowlerDF,<bowlerName>)

# Wickets at venue
#yka.bowlerWicketsVenue(bowlerDF,<bowlerName>)

Important note: Do check out my other posts using yorkpy at yorkpy-posts
``````

## Conclusion

With the above templates detailed analyis can be done on

• A T20 match
• Performance of a team in all matches against another team
• Performance of a team in all matches against all other teams
• Individual batting and bowling performances

To see all posts click Index of posts

# yorkpy takes a hat-trick, bowls out Intl. T20s, BBL and Natwest T20!!!

“Dear, dear! How queer everything is to-day! And yesterday things went on just as usual. I wonder if I’ve been changed in the night? Let me think: was I the same when I got up this morning? I almost think I can remember feeling a little different. But if I’m not the same, the next question is ’Who in the world am I? Ah, that’s the great puzzle!”

``             Alice's adventures  in Wonderland, Lewis Carroll``

## 1. Introduction

In this post, yorkpy clean bowls the following T20 formats namely International T20s, Big Bash League and Natwest T20 Blast. I take yorkpy on a spin through these T20 leagues. In the post below,I choose a random set of about 10-12 of the overall 63 functions that yorkpy has, and execute them for each of the different T20 leagues – Intl T20s, BBL and Natwest T20s. yorkpy, is the python avatar of my R package yorkr, see Introducing cricket package yorkr: Part 1- Beaten by sheer pace!

There were a couple of new functions that needed to be added for each of the T20 leagues – Intl T20, BBL and Natwest T20 to take into account the different teams in each of these leagues. Further some bugs were also ironed out in tje latest version of yorkpy. yorkpy uses data from Cricsheet . The match data is in the form of YAML files. yorkpy converts these YAML files to dataframes. YAML files are very detailed and include a ball-by-ball account of the match.

– You can clone/fork the latest code for yorkpy from github yorkpy
– This post has also been published in RPubs at yorkpy takes a hat-trick

The data for IPL, Intl. T20, BBL and Natwest T20 have already been converted into pandas dataframes and saved as CSVs. You can download the converted files from Github at [allYorkpyT20Data])(https://github.com/tvganesh/allYorkpyT20Data)

yorkpy has the following 4 main classes of functions

### A.Functions analyzing individual T20 match (Class 1)

This was demonstrated in Pitching yorkpy . short of good length to IPL – Part 1 The functions deal with individual T20 matches. The functions are

1. convertYaml2PandasDataframeT20()
2. convertAllYaml2PandasDataframesT20()
3. teamBattingScorecardMatch()
4. teamBatsmenPartnershipMatch()
5. teamBatsmenVsBowlersMatch()
6. teamBowlingScorecardMatch()
7. teamBowlingWicketKindMatch()
8. teamBowlingWicketRunsMatch()
9. teamBowlingWicketMatch()
10. teamBowlersVsBatsmenMatch()
11. matchWormChart()

### B. Functions that analyze all matches between 2 T20 teams (Class 2

Pitching yorkpy.on the middle and outside off-stump to IPL – Part 2 included functions that analyze head-to-head confrontation between any 2 T20 teams The functions are

1. getAllMatchesBetweenTeams()
2. saveAllMatchesBetween2IPLTeams()
3. getAllMatchesBetweenTeams()
4. saveAllMatchesBetween2IPLTeams()
5. teamBatsmenPartnershiOppnAllMatches()
6. teamBatsmenPartnershipOppnAllMatchesChart()
7. teamBatsmenVsBowlersOppnAllMatches()
8. teamBattingScorecardOppnAllMatches()
9. teamBowlingScorecardOppnAllMatches()
10. teamBowlingWicketKindOppositionAllMatches()
11. teamBowlersVsBatsmenOppnAllMatches()
12. plotWinLossBetweenTeams()
13. plotWinsByRunOrWickets() 23.plotWinsbyTossDecision()

### C. Functions that analyze the performance of a T20 team against all other teams (Class 3)

The post Pitching yorkpy.swinging away from the leg stump to IPL – Part 3 is based on Class C set of functions shown below

1. getAllMatchesAllOpposition()
2. saveAllMatchesAllOppositionIPLT20(dir1)
3. getAllMatchesAllOpposition()
4. saveAllMatchesAllOppositionIPLT20()
5. teamBatsmenPartnershiAllOppnAllMatches()
6. teamBatsmenPartnershipAllOppnAllMatchesChart()
7. teamBatsmenVsBowlersAllOppnAllMatches()
8. teamBattingScorecardAllOppnAllMatches()
9. teamBowlingScorecardAllOppnAllMatches()
10. teamBowlingWicketKindAllOppnAllMatches()
11. teamBowlersVsBatsmenAllOppnAllMatches()
12. plotWinLossByTeamAllOpposition()
13. plotWinsByRunOrWicketsAllOpposition()
14. plotWinsbyTossDecisionAllOpposition()

### D. Functions that analyze performances of T20 batsmen and bowlers (Class 4)

These set of functions analyze individual batsmen and bowlers and have been used in Pitching yorkpy . in the block hole – Part 4 The functions are

1. getTeamBattingDetails()
2. getBatsmanDetails()
3. batsmanRunsVsDeliveries()
5. batsmanDismissals()
6. batsmanRunsVsStrikeRate()
7. batsmanMovingAverage()
8. batsmanCumulativeAverageRuns()
9. batsmanCumulativeStrikeRate()
10. batsmanRunsAgainstOpposition()
11. batsmanRunsVenue
12. getTeamBowlingDetails()
13. getBowlerWicketDetails()
14. bowlerMeanEconomyRate()
15. bowlerMeanRunsConceded()
16. bowlerMovingAverage()
17. bowlerCumulativeAvgWickets()
18. bowlerCumulativeAvgEconRate()
19. bowlerWicketPlot()
20. bowlerWicketsAgainstOpposition()
21. bowlerWicketsVenue()

Additional new functions were added to handle Intl T20s, Big Bash League and Natwest T20 Blast, since the teams are different. They are

59. saveAllMatchesBetween2IntlT20s()
60. saveAllMatchesAllOppositionIntlT20()
61. saveAllMatchesBetween2BBLTeams()
62 saveAllMatchesAllOppositionBBLT20()
63. saveAllMatchesBetween2NWBTeams()
64. saveAllMatchesAllOppositionNWBT20()

All other functions can be used as is! You can get the help of any function in yorkpy using

``````import yorkpy.analytics as yka
help(yka.teamBatsmenPartnershiOppnAllMatches)``````
``````## Help on function teamBatsmenPartnershiOppnAllMatches in module yorkpy.analytics:
##
## teamBatsmenPartnershiOppnAllMatches(matches, theTeam, report='summary', top=5)
##     Team batting partnership against a opposition all IPL matches
##
##     Description
##
##     This function computes the performance of batsmen against all bowlers of an oppositions in
##     all matches. This function returns a dataframe
##
##     Usage
##
##     teamBatsmenPartnershiOppnAllMatches(matches,theTeam,report="summary")
##     Arguments
##
##     matches
##     All the matches of the team against the oppositions
##     theTeam
##     The team for which the the batting partnerships are sought
##     report
##     If the report="summary" then the list of top batsmen with the highest partnerships
##     is displayed. If report="detailed" then the detailed break up of partnership is returned
##     as a dataframe
##     top
##     The number of players to be displayed from the top
##     Value
##
##     partnerships The data frame of the partnerships
##
##     Note
##
##     Maintainer: Tinniam V Ganesh tvganesh.85@gmail.com
##
##     Author(s)
##
##     Tinniam V Ganesh
##
##     References
##
##     http://cricsheet.org/
##
##
##
##     teamBatsmenVsBowlersOppnAllMatchesPlot
##     teamBatsmenPartnershipOppnAllMatchesChart``````

As I mentioned above I will be randomly choosing a set of 12 functions from Class 1,2,3,4 for each of the T20 leagues (Intl T20, BBL and NWB T20) for analysis

## 2. International T20s

The following functions were added for handling Intl. T20s

1. saveAllMatchesBetween2IntlT20s()
2. saveAllMatchesAllOppositionIntlT20()

To handle the countries in Intl. T20s below

Afghanistan, Australia, Bangladesh, Bermuda, Canada, England,Hong Kong,India, Ireland, Kenya, Nepal, Netherlands, “New Zealand, Oman,Pakistan,Scotland,South Africa, Sri Lanka, United Arab Emirates,West Indies, Zimbabwe

``````import os
#os.chdir('C:\\software\\cricket-package\\yorkpyT20\\t20s')
#import yorkpy.analytics as yka
#1.  Convert all YAML files to dataframes and CSV
#yka.convertAllYaml2PandasDataframesT20(".", "..\\data1")
#dir1='C:\\software\\cricket-package\\yorkpyT20\\IntlT20-Matches'
#2. Save all matches between 2 T20 teams
#yka.saveAllMatchesBetween2IntlT20s(dir1)
#3. Save all matches between a T20 team and all other teams
#dir1='C:\\software\\cricket-package\\yorkpyT20\\IntlT20-Matches'
#yka.saveAllMatchesAllOppositionIntlT20(dir1)
#4. Get batting details
#dir1='C:\\software\\cricket-package\\yorkpyT20\\IntlT20-Matches
#yka.getTeamBattingDetails("Afghanistan",dir=dir1, save=True)
#yka.getTeamBattingDetails("Australia",dir=dir1,save=True)
#...
#5. Get bowling details
#dir1='C:\\software\\cricket-package\\yorkpyT20\\IntlT20-Matches
#yka.getTeamBowlingDetails("Afghanistan",dir=dir1, save=True)
#yka.getTeamBowlingDetails("Australia",dir=dir1,save=True)
# ...``````

Once the data is converted you can use the yorkpy functions. The data has been converted for Intl T20 and is available at Github at IntlT20

To use the yorkpy functions for a new league we need to initial convert the YAML files into appropriate format for processing by yorkpy functions

This will create the necessary files which are are used in the functions below

### 2.2 2.1 Intl. T20 – Team score card  (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyT20\\IntlT20-Matches"
path=os.path.join(dir1,".\\India-New Zealand-2007-09-16.csv")
scorecard,extras=yka.teamBattingScorecardMatch(ind_nz,"India")
print(scorecard)``````
``````##             batsman  runs  balls  4s  6s          SR
## 0         G Gambhir    51     34   5   2  150.000000
## 1          V Sehwag    40     18   6   2  222.222222
## 2        RV Uthappa     0      2   0   0    0.000000
## 3          MS Dhoni    24     20   2   0  120.000000
## 4      Yuvraj Singh     5      7   0   0   71.428571
## 5        KD Karthik    17     12   3   0  141.666667
## 6         IK Pathan    11     10   2   0  110.000000
## 7        AB Agarkar     1      2   0   0   50.000000
## 8   Harbhajan Singh     7      6   1   0  116.666667
## 9       S Sreesanth    19     10   4   0  190.000000
## 10         RP Singh     1      1   0   0  100.000000``````
``print(extras)``
``````##    total  wides  noballs  legbyes  byes  penalty  extras
## 0    370      6        0        8     0        0      14``````

### 2.2 Intl. T20 -Team batsmen partnership (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyT20\\IntlT20-Matches"
path=os.path.join(dir1,".\\South Africa-Australia-2009-03-27.csv")
yka.teamBatsmenPartnershipMatch(sa_aus,'Australia','New Zealand',plot=True)``````

### 2.3 Intl. T20 -Team bowling scorecard match (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyT20\\IntlT20-Matches"
path=os.path.join(dir1,".\\Sri Lanka-West Indies-2012-09-28.csv")
a=yka.teamBowlingScorecardMatch(sl_wi,'Sri Lanka')``````
``print(a)``
``````##          bowler  overs  runs  maidens  wicket  econrate
## 0    A Mohammed      2    13        0       0       6.5
## 1  SA Campbelle      1     8        0       1       8.0
## 2     SC Selman      1     3        0       0       3.0
## 3      SF Daley      2     5        0       1       2.5
## 4     SR Taylor      2     4        0       1       2.0
## 5     TD Smartt      2    17        0       0       8.5``````

### 2.4 Intl. T20 -Match Worm chart (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyT20\\IntlT20-Matches"
path=os.path.join(dir1,".\\England-India-2012-09-29.csv")
yka.matchWormChart(eng_ind,"England", "India")``````

``````path=os.path.join(dir1,".\\Bangladesh-Ireland-2015-12-05.csv")

### 2.5 Intl. T20 -Team Batting partnerships all matches 2 teams (Class 2)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyT20\\IntlT20-allMatchesBetween2Teams"
path=os.path.join(dir1,"India-England-allMatches.csv")
theTeam='India'
m=yka.teamBatsmenPartnershiOppnAllMatches(dc_mi_matches,theTeam,report="detailed", top=4)
print(m)``````
``````##      batsman  totalPartnershipRuns    non_striker  partnershipRuns
## 0   SK Raina                   265      G Gambhir                2
## 1   SK Raina                   265       KL Rahul               40
## 2   SK Raina                   265      MK Tiwary               24
## 3   SK Raina                   265       MS Dhoni              124
## 4   SK Raina                   265        P Kumar                0
## 5   SK Raina                   265      PP Chawla                4
## 6   SK Raina                   265       R Ashwin                1
## 7   SK Raina                   265      RG Sharma               16
## 8   SK Raina                   265        V Kohli               47
## 9   SK Raina                   265   Yuvraj Singh                7
## 10  MS Dhoni                   264       A Mishra                1
## 11  MS Dhoni                   264      AT Rayudu               18
## 12  MS Dhoni                   264      HH Pandya                8
## 13  MS Dhoni                   264      IK Pathan                2
## 14  MS Dhoni                   264      JJ Bumrah                2
## 15  MS Dhoni                   264      MK Pandey                3
## 16  MS Dhoni                   264  Parvez Rasool               21
## 17  MS Dhoni                   264       R Ashwin               11
## 18  MS Dhoni                   264      RA Jadeja               11
## 19  MS Dhoni                   264      RG Sharma                9
## 20  MS Dhoni                   264        RR Pant                6
## 21  MS Dhoni                   264     RV Uthappa                5
## 22  MS Dhoni                   264       SK Raina               98
## 23  MS Dhoni                   264      YK Pathan               36
## 24  MS Dhoni                   264   Yuvraj Singh               33
## 25   V Kohli                   236      AM Rahane                3
## 26   V Kohli                   236      G Gambhir               78
## 27   V Kohli                   236       KL Rahul               46
## 28   V Kohli                   236      RG Sharma                2
## 29   V Kohli                   236     RV Uthappa                4
## 30   V Kohli                   236       S Dhawan               45
## 31   V Kohli                   236       SK Raina               48
## 32   V Kohli                   236   Yuvraj Singh               10
## 33     M Raj                   176       A Sharma                2
## 34     M Raj                   176         H Kaur               18
## 35     M Raj                   176      J Goswami                6
## 36     M Raj                   176        KV Jain                5
## 37     M Raj                   176       L Kumari                5
## 38     M Raj                   176    N Niranjana                3
## 39     M Raj                   176       N Tanwar               17
## 40     M Raj                   176        PG Raut               41
## 41     M Raj                   176     R Malhotra                5
## 42     M Raj                   176     S Mandhana                8
## 43     M Raj                   176         S Naik               10
## 44     M Raj                   176       S Pandey               19
## 45     M Raj                   176       SK Naidu               37``````

### 2.6 Intl. T20 -Team Batsmen vs Bowlers all matches 2 teams (Class 2)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyT20\\IntlT20-allMatchesBetween2Teams"
path=os.path.join(dir1,"Ireland-Netherlands-allMatches.csv")
yka.teamBatsmenVsBowlersOppnAllMatches(ire_nl_matches,'Ireland',"Netherlands",plot=True,top=3,runsScored=10)``````

### 2.7 Intl. T20 -Team Bowling scorecard all matches 2 teams (Class 2)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyT20\\IntlT20-allMatchesBetween2Teams"
print(scorecard)``````
``````##         bowler  overs  runs  maidens  wicket   econrate
## 0      B Regmi      3    14        0       1   4.666667
## 3   SP Gauchan      4    40        0       1  10.000000
## 1   JK Mukhiya      2    16        0       0   8.000000
## 2     P Khadka      3    23        0       0   7.666667
## 4    Sagar Pun      1    16        0       0  16.000000
## 5  Sompal Kami      2    21        0       0  10.500000``````

### 2.8 Intl. T20 -Team Batsmen vs Bowlers all Oppositions (Class 3)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyT20\\\IntlT20-allMatchesAllOpposition\\"
path=os.path.join(dir1,"Australia-allMatchesAllOpposition.csv")
yka.teamBatsmenVsBowlersAllOppnAllMatches(aus_matches,"Australia",plot=True,top=3,runsScored=40)``````

### 2.9 Intl. T20 -Wins vs Losses of a team against all other teams (Class 3)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyT20\\\IntlT20-allMatchesAllOpposition\\"
path=os.path.join(dir1,"South Africa-allMatchesAllOpposition.csv")
team1='South Africa'
yka.plotWinLossByTeamAllOpposition(sa_matches,team1,plot="detailed")``````

### 2.10 Intl. T20 -Batsmen analysis (Class 4)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyT20\\\IntlT20-BattingBowlingDetails\\"
# Rohit Sharma
name="RG Sharma"
team='India'
df=yka.getBatsmanDetails(team,name,dir=dir1)
yka.batsmanCumulativeAverageRuns(df,name)``````

``````# MJ Guptill
name="MJ Guptill"
team='New Zealand'
df=yka.getBatsmanDetails(team,name,dir=dir1)
yka.batsmanCumulativeStrikeRate(df,name)``````

### 2.11 Intl. T20 -Bowler analysis (Class 4)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyT20\\\IntlT20-BattingBowlingDetails\\"
# Shakib Al Hasan
name="Shakib Al Hasan"
df=yka.getBowlerWicketDetails(team,name,dir=dir1)
yka.bowlerMeanEconomyRate(df,name)``````

``````# Rashid Khan
name="SL Malinga"
team='Sri Lanka'
df=yka.getBowlerWicketDetails(team,name,dir=dir1)
yka.bowlerWicketsAgainstOpposition(df,name)``````

## 3. Big Bash League

The following functions for added to handle BBL teams

1. saveAllMatchesBetween2BBLTeams()
2. saveAllMatchesAllOppositionBBLT20

The BBL teams are included are Adelaide Strikers, Brisbane Heat, Hobart Hurricanes, Melbourne Renegades, Perth Scorchers, Sydney Sixers, Sydney Thunder

To use the yorkpy functions first the YAML files have to be converted into pandas dataframe and then saved as CSV as shown below

``````import os
import yorkpy.analytics as yka
os.chdir('C:\\software\\cricket-package\\yorkpyBBL\\bbl')
#1. Convert all YAML files to dataframes and save as CSV
#yka.convertAllYaml2PandasDataframesT20(".", "..\\BBLT20-Matches")
#2. Save all matches between 2 BBL teams
dir1='C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-Matches'
#yka.saveAllMatchesBetween2BBLTeams(dir1)
#3. Save T20 matches between a BBL team and all other teams
dir1='C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-Matches'
#yka.saveAllMatchesAllOppositionBBLT20(dir1)
#4. Get the batting details
dir1='C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-Matches'
#yka.getTeamBattingDetails("Brisbane Heat",dir=dir1,save=True)
#yka.getTeamBattingDetails("Hobart Hurricanes",dir=dir1,save=True)
#...
# Get the bowling details
dir1='C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-Matches'
#yka.getTeamBowlingDetails("Brisbane Heat",dir=dir1,save=True)
#yka.getTeamBowlingDetails("Hobart Hurricanes",dir=dir1,save=True)
#...``````

The functions below perform analysis on the generated files from above. The YAML files have already been converted and are available at Github at BBL

### 3.1 Big Bash League – Team score card (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-Matches"
scorecard,extras=yka.teamBattingScorecardMatch(as_bh,"Brisbane Heat")
print(scorecard)``````
``````##          batsman  runs  balls  4s  6s          SR
## 0  LA Pomersbach    65     42   8   2  154.761905
## 1       JR Hopes     1      2   0   0   50.000000
## 2       JA Burns    37     31   2   2  119.354839
## 3   DT Christian    12     15   0   0   80.000000
## 4    NLTC Perera    12      4   0   2  300.000000
## 5        CA Lynn    19     18   1   1  105.555556
## 6    BCJ Cutting    13      5   0   2  260.000000
## 7     PJ Forrest    12      8   0   1  150.000000
## 8     CD Hartley     5      2   1   0  250.000000``````
``print(extras)``
``````##    total  wides  noballs  legbyes  byes  penalty  extras
## 0    371     10        2        5     0        0      17``````

### 3.2 Big Bash League -Team batsmen vs Bowlers (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-Matches"

### 3.3 Big Bash League -Team bowling scorecard match (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-Matches"
path=os.path.join(dir1,".\\Melbourne Stars-Sydney Thunder-2016-01-24.csv")
a=yka.teamBowlingScorecardMatch(ms_st,'Sydney Thunder')
print(a)``````
``````##           bowler  overs  runs  maidens  wicket   econrate
## 0        A Zampa      4    32        0       2   8.000000
## 1  BW Hilfenhaus      2    21        0       0  10.500000
## 2      DJ Hussey      1     9        0       1   9.000000
## 3     DJ Worrall      3    42        0       0  14.000000
## 4      EP Gulbis      2    19        0       0   9.500000
## 5        MA Beer      3    25        0       1   8.333333
## 6     MP Stoinis      4    30        0       3   7.500000``````

### 3.4 Big Bash League – Match Worm chart (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-Matches"
path=os.path.join(dir1,".\\Sydney Sixers-Melbourne Stars-2011-12-27.csv")
yka.matchWormChart(ss_ms,"Melbourne Stars", "Sydney Sixers")``````

``````path=os.path.join(dir1,".\\Hobart Hurricanes-Brisbane Heat-2015-01-02.csv")
yka.matchWormChart(hh_bh,"Hobart Hurricanes", "Brisbane Heat")``````

### 3.5 Big Bash League -Team Batting partnerships all matches 2 teams (Class 2)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-allMatchesBetween2Teams"

### 3.6 Big Bash League -Team Bowling wicket kind all matches 2 teams (Class 2)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-allMatchesBetween2Teams"
path=os.path.join(dir1,"Sydney Sixers-Perth Scorchers-allMatches.csv")
yka.teamBowlingWicketKindOppositionAllMatches(ss_ps_matches,'Perth Scorchers','Sydney Sixers',plot=True,top=5,wickets=1)``````

### 3.7 Big Bash League -Team Bowling scorecard all teams (Class 3)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-allMatchesAllOpposition"
path=os.path.join(dir1,"Hobart Hurricanes-allMatchesAllOpposition.csv")
scorecard=yka.teamBowlingScorecardAllOppnAllMatches(hh_matches,"Hobart Hurricanes")
print(scorecard)``````
``````##              bowler  overs  runs  maidens  wicket   econrate
## 16            B Lee     20   132        0       9   6.600000
## 30         CJ McKay     13   110        0       9   8.461538
## 88    NJ Rimmington     16   103        1       9   6.437500
## 67      JW Hastings     15    88        0       8   5.866667
## 63      JP Faulkner     15   146        0       7   9.733333
## 27        CJ Gannon     17   147        1       7   8.647059
## 93          NM Lyon      8    51        0       7   6.375000
## 20      BCJ Cutting     27   226        0       7   8.370370
## 48          GB Hogg     22   167        0       7   7.590909
## 107       SM Boland     12    96        0       7   8.000000
## 15       B Laughlin     13    99        0       7   7.615385
## 87      MT Steketee     15   134        0       5   8.933333
## 121    Yasir Arafat      9    48        0       4   5.333333
## 96       PJ Cummins      8    83        0       4  10.375000
## 46      Fawad Ahmed     11    64        0       4   5.818182
## 76          MA Beer     12    63        0       4   5.250000
## 108     SNJ O'Keefe     15   104        0       4   6.933333
## 75   M Muralitharan      7    31        0       4   4.428571
## 10           AJ Tye     16   127        0       4   7.937500
## 52          J Botha     13    94        0       4   7.230769
## 56     JL Pattinson      7    71        0       4  10.142857
## 62   JP Behrendorff     16   119        0       4   7.437500
## 3           AC Agar     12    87        0       4   7.250000
## 24     BM Edmondson      4    40        0       4  10.000000
## 37        DJ Hussey      8    47        0       3   5.875000
## 49       GJ Maxwell      8    65        0       3   8.125000
## 84       MN Samuels      4    22        0       3   5.500000
## 81         MG Neser      5    54        0       3  10.800000
## 44     DT Christian      9   114        0       3  12.666667
## 50        GS Sandhu      7    51        0       3   7.285714
## ..              ...    ...   ...      ...     ...        ...
## 43        DP Nannes      8    58        0       1   7.250000
## 51         IA Moran      4    25        0       1   6.250000
## 55         JK Lalor     10    82        0       1   8.200000
## 54        JH Kallis      3    18        0       1   6.000000
## 73   LR Butterworth      4    25        0       1   6.250000
## 4      AC McDermott      2    28        0       1  14.000000
## 70         LA Doran      4    38        0       1   9.500000
## 69    KW Richardson      6    44        0       1   7.333333
## 119     WD Sheridan      2     6        0       0   3.000000
## 2       AB McDonald      1    15        0       0  15.000000
## 115      TD Andrews      3    23        0       0   7.666667
## 11          AK Heal      4    33        0       0   8.250000
## 7        AD Russell      4    40        0       0  10.000000
## 8          AJ Finch      2    15        0       0   7.500000
## 9         AJ Turner      3    28        0       0   9.333333
## 60        JM Mennie      1    20        0       0  20.000000
## 18        BA Stokes      1     9        0       0   9.000000
## 26         CH Gayle      1    16        0       0  16.000000
## 28         CJ Green      4    44        0       0  11.000000
## 95   PD Collingwood      2    20        0       0  10.000000
## 31       CJ Simmons      4    21        0       0   5.250000
## 59       JM Holland      3    34        0       0  11.333333
## 36         DJ Bravo      6    64        0       0  10.666667
## 38     DJ Pattinson      2    16        0       0   8.000000
## 41       DJ Worrall      8    90        0       0  11.250000
## 72      LN O'Connor      6    56        0       0   9.333333
## 71        LJ Wright      3    27        0       0   9.000000
## 68       KA Pollard      1     7        0       0   7.000000
## 58       JM Herrick      4    23        0       0   5.750000
## 92       NM Hauritz      5    42        0       0   8.400000
##
## [122 rows x 6 columns]``````

### 3.8 Big Bash League -Plot wins vs losses against all teams(Class 3)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-allMatchesAllOpposition"
path=os.path.join(dir1,"Sydney Sixers-allMatchesAllOpposition.csv")
yka.plotWinLossByTeamAllOpposition(ss_matches,'Sydney Sixers')``````

### 3.9 Big Bash League -Wins vs losses by toss decision (Class 3)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-allMatchesAllOpposition"

### 3.10 Big Bash League -Batsmen Analysis (Class 4)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-BattingBowlingDetails"
# CA Lynn
name="CA Lynn"
team='Brisbane Heat'
df=yka.getBatsmanDetails(team,name,dir=dir1)
yka.batsmanRunsVsStrikeRate(df,name)``````

``````# UT Khawaja
name="UT Khawaja"
team='Sydney Thunder'
df=yka.getBatsmanDetails(team,name,dir=dir1)
yka.batsmanRunsAgainstOpposition(df,name)``````

### 3.11Big Bash League – Bowler analysis (Class 4)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyBBL\\BBLT20-BattingBowlingDetails"
# CJ McKay
name="CJ McKay"
team='Sydney Thunder'
df=yka.getBowlerWicketDetails(team,name,dir=dir1)
yka.bowlerCumulativeAvgWickets(df,name)``````

``````# AU Rashid
name="AU Rashid"
df=yka.getBowlerWicketDetails(team,name,dir=dir1)
yka.bowlerCumulativeAvgEconRate(df,name)``````

## 4. Natwest T20 Blast

The following functions for added to handle Natwest T20 teams

1. saveAllMatchesBetween2NWBTeams()
2. saveAllMatchesAllOppositionNWBT20

The Natwest teams are
Derbyshire, Durham, Essex, Glamorgan, Gloucestershire, Hampshire, Kent,Lancashire, Leicestershire, Middlesex,Northamptonshire, Nottinghamshire, Somerset, Surrey, Sussex, Warwickshire, Worcestershire,Yorkshire

In order to perform analysis with yorkpy, the YAML data has to be converted to pandas dataframe and saves as CSV as shown

``````#import os
#import yorkpy.analytics as yka
#os.chdir('C:\\software\\cricket-package\\yorkpyNWB\\nwb')
#1. Convert YAML to dataframes and save as CSV
#yka.convertAllYaml2PandasDataframesT20(".", "..\\NWBT20-Matches")
#2. Save all matches between 2 NWBT20 teams
#dir1='C:\\software\\cricket-package\\yorkpyNWB\\NWBT20-Matches'
#yka.saveAllMatchesBetween2NWBTeams(dir1)
#3. Save all matches between a NWB T20 team and all other teams
#dir1='C:\\software\\cricket-package\\yorkpyNWB\\NWBT20-Matches'
#yka.saveAllMatchesAllOppositionNWBT20(dir1)
#4. Compute the batting details
dir1='C:\\software\\cricket-package\\yorkpyNWB\\NWBT20-Matches'
#yka.getTeamBattingDetails("Derbyshire",dir=dir1, save=True)
#yka.getTeamBattingDetails("Durham",dir=dir1,save=True)
#yka.getTeamBattingDetails("Essex",dir=dir1,save=True)
#..
#5. Compute bowling details
dir1='C:\\software\\cricket-package\\yorkpyNWB\\NWBT20-Matches'
#yka.getTeamBowlingDetails("Derbyshire",dir=dir1, save=True)
#yka.getTeamBowlingDetails("Durham",dir=dir1,save=True)
#yka.getTeamBowlingDetails("Essex",dir=dir1,save=True)
#...``````

Once the data is converted all yorkpy functions can be used. This has already been done and is available at github NWB

### 4.1 Natwest T20 Blast – Team score card (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\\yorkpyNWB\\NWBT20-Matches"
path=os.path.join(dir1,".\\Durham-Yorkshire-2016-08-20.csv")
scorecard,extras=yka.teamBattingScorecardMatch(d_y,"Durham")
print(scorecard)``````
``````##           batsman  runs  balls  4s  6s          SR
## 0     MD Stoneman    25     20   4   0  125.000000
## 1     KK Jennings    11     13   1   0   84.615385
## 2       BA Stokes    56     37   4   3  151.351351
## 3   MJ Richardson    29     23   4   1  126.086957
## 4     JTA Burnham    17     15   1   1  113.333333
## 5      RD Pringle    10      9   1   0  111.111111
## 6  PD Collingwood     2      3   0   0   66.666667
## 7        U Arshad     1      1   0   0  100.000000``````
``print(extras)``
``````##    total  wides  noballs  legbyes  byes  penalty  extras
## 0    305      2        0        5     0        0       7``````

### 4.2 Natwest T20 Blast -Team batsmen vs Bowlers (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\\yorkpyNWB\\NWBT20-Matches"
path=os.path.join(dir1,".\\Derbyshire-Lancashire-2016-07-13.csv")
yka.teamBatsmenVsBowlersMatch(d_l,'Lancashire','Derbyshire',plot=True)``````

### 4.3 Natwest T20 Blast -Team bowling scorecard match (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\\yorkpyNWB\\NWBT20-Matches"
path=os.path.join(dir1,".\\Essex-Surrey-2016-05-20.csv")
a=yka.teamBowlingScorecardMatch(e_s,'Essex')
print(a)``````
``````##           bowler  overs  runs  maidens  wicket   econrate
## 0  Azhar Mahmood      3    38        0       4  12.666667
## 1       GJ Batty      4    33        0       1   8.250000
## 2       JE Burke      1    18        0       0  18.000000
## 3     MW Pillans      3    28        0       0   9.333333
## 4      SM Curran      4    23        0       2   5.750000
## 5      TK Curran      4    21        0       3   5.250000``````

### 4.4 Natwest T20 Blast -Match Worm chart (Class 1)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\\yorkpyNWB\\NWBT20-Matches"
path=os.path.join(dir1,".\\Gloucestershire-Glamorgan-2016-06-10.csv")
yka.matchWormChart(ss_ms,"Gloucestershire", "Glamorgan")``````

``````path=os.path.join(dir1,".\\Leicestershire-Northamptonshire-2016-05-20.csv")
yka.matchWormChart(hh_bh,"Northamptonshire", "Leicestershire")``````

### 4.5 Natwest T20 Blast -Team Batting partnerships all matches 2 teams (Class 2)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyNWB\\NWBT20-allMatchesBetween2Teams"
path=os.path.join(dir1,"Hampshire-Sussex-allMatches.csv")
yka.teamBatsmenPartnershipOppnAllMatchesChart(h_s_matches,"Hampshire","Sussex",plot=True, top=4, partnershipRuns=10)``````

### 4.6 Natwest T20 Blast -Team Bowling wicket kind all matches 2 teams (Class 2)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyNWB\\NWBT20-allMatchesBetween2Teams"
path=os.path.join(dir1,"Kent-Somerset-allMatches.csv")
yka.teamBowlersVsBatsmenOppnAllMatches(k_s_matches,'Kent','Somerset',plot=True,
top=5,runsConceded=10)``````

### 4.7 Natwest T20 Blast -Team Bowling scorecard all teams (Class 3)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyNWB\\NWBT20-allMatchesAllOpposition"
path=os.path.join(dir1,"Middlesex-allMatchesAllOpposition.csv")
scorecard=yka.teamBowlingScorecardAllOppnAllMatches(m_matches,"Middlesex")
print(scorecard)``````
``````##               bowler  overs  runs  maidens  wicket   econrate
## 1             AJ Tye      8    75        0       6   9.375000
## 5         BAC Howell      8    41        0       5   5.125000
## 26         GR Napier      7    65        0       5   9.285714
## 15        DI Stevens      4    31        0       4   7.750000
## 19       DW Lawrence      6    37        0       4   6.166667
## 32       JW Dernbach      4    33        0       3   8.250000
## 7          BTJ Wheal      4    43        0       3  10.750000
## 18         DR Briggs      4    24        0       3   6.000000
## 50     RK Kleinveldt      4    24        0       3   6.000000
## 46         R McLaren      7    59        0       3   8.428571
## 47         R Rampaul      3    21        0       3   7.000000
## 34         L Gregory      6    51        0       2   8.500000
## 33   KMDN Kulasekara      2    24        0       2  12.000000
## 40          MG Hogan      3    17        0       2   5.666667
## 43        MTC Waller      4    31        0       2   7.750000
## 49        RJ Gleeson      4    20        0       2   5.000000
## 48  RE van der Merwe      5    24        0       2   4.800000
## 51  RN ten Doeschate      4    32        0       2   8.000000
## 53        S Prasanna      4    20        0       2   5.000000
## 56           SW Tait      3    17        0       2   5.666667
## 57     Shahid Afridi      8    55        0       2   6.875000
## 59  T van der Gugten      3    13        1       2   4.333333
## 64          TS Mills      3    34        0       2  11.333333
## 65          WAT Beer      4    23        0       2   5.750000
## 31          JH Davey      4    28        0       2   7.000000
## 68         ZS Ansari      3    16        0       2   5.333333
## 25         GM Andrew      3    19        0       2   6.333333
## 23          GJ Batty      6    55        0       2   9.166667
## 16          DJ Bravo      3    27        0       2   9.000000
## 41          MR Quinn      6    65        0       1  10.833333
## ..               ...    ...   ...      ...     ...        ...
## 24     GL van Buuren      7    49        0       1   7.000000
## 37           MD Hunn      3    35        0       1  11.666667
## 36        LC Norwell      6    62        0       1  10.333333
## 29       JC Tredwell      4    35        0       1   8.750000
## 35         LA Dawson      6    53        0       1   8.833333
## 62           TL Best      4    51        0       0  12.750000
## 58         T Westley      2    12        0       0   6.000000
## 4         Azharullah      3    24        0       0   8.000000
## 60     TD Groenewald      1    21        0       0  21.000000
## 61         TK Curran      4    35        0       0   8.750000
## 38         MD Taylor      3    30        0       0  10.000000
## 30        JG Myburgh      1     5        0       0   5.000000
## 8          C Overton      2    18        0       0   9.000000
## 2        Ashar Zaidi      1     5        0       0   5.000000
## 66          WR Smith      2    25        0       0  12.500000
## 28         J Overton      2    24        0       0  12.000000
## 6          BJ Taylor      1     6        0       0   6.000000
## 22          GG White      4    31        0       0   7.750000
## 55          SP Crook      1     9        0       0   9.000000
## 39        ME Claydon      4    40        0       0  10.000000
## 52         RS Bopara      4    32        0       0   8.000000
## 10           CD Nash      2    19        0       0   9.500000
## 11         CH Morris      4    36        0       0   9.000000
## 12         DA Cosker      3    32        0       0  10.666667
## 13      DA Griffiths      4    39        0       0   9.750000
## 45          PD Trego      1    11        0       0  11.000000
## 44   PA van Meekeren      2    19        0       0   9.500000
## 42          MS Crane      2    25        0       0  12.500000
## 20        FK Cowdrey      1    19        0       0  19.000000
## 14        DD Masters      2    16        0       0   8.000000
##
## [69 rows x 6 columns]``````

### 4.8 Natwest T20 Blast -Plot wins vs losses against all teams(Class 3)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyNWB\\NWBT20-allMatchesAllOpposition"
path=os.path.join(dir1,"Warwickshire-allMatchesAllOpposition.csv")
yka.plotWinLossByTeamAllOpposition(w_matches,'Warwickshire')``````

### 4.9 Natwest T20 Blast -Batsmen Analysis (Class 4)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyNWB\\NWBT20-BattingBowlingDetails"
# M Klinger
name="M Klinger"
team='Gloucestershire'
df=yka.getBatsmanDetails(team,name,dir=dir1)
yka.batsmanRunsAgainstOpposition(df,name)``````

``````# CA Ingram
name="CA Ingram"
team='Glamorgan'
df=yka.getBatsmanDetails(team,name,dir=dir1)
yka.batsmanCumulativeStrikeRate(df,name)``````

### 4.11 Natwest T20 Blast -Bowler analysis (Class 4)

``````import os
import pandas as pd
import yorkpy.analytics as yka
dir1="C:\\software\\cricket-package\\yorkpyNWB\\NWBT20-BattingBowlingDetails"
# BAC Howell
name="BAC Howell"
team='Gloucestershire'
df=yka.getBowlerWicketDetails(team,name,dir=dir1)
yka.bowlerCumulativeAvgEconRate(df,name)``````

``````# GR Napier
name="GR Napier"
team='Essex'
df=yka.getBowlerWicketDetails(team,name,dir=dir1)
yka.bowlerWicketsVenue(df,name)``````

Note: yorkpy will work for all T20 leagues which are in YAML format as specified in Cricsheet.

You can clone/fork the latest code for yorkpy from github yorkpy

The data for IPL, Intl. T20, BBL and Natwest T20 have already been converted into pandas dataframes and saved as CSVs. You can download the converted files from Github at [allYorkpyT20Data])(https://github.com/tvganesh/allYorkpyT20Data)

Conclusion This post shows the kind of detailed analysis that can be performed with yorkpy. In fact with all the converted data it should be possible to also train a Machine Learning model, which I will probably keep for another day. You could go ahead and use the data in other innovative ways. Do keep me posted if you do!!

Important note: Do check out my other posts using yorkpy at yorkpy-posts

Have fun with yorkpy!!

To see all posts click Index of posts