Welcome to the Cannabis Data Science Meetup Group for the 1st of September.
I hope everybody's doing well.
Crunching numbers here in Oklahoma again.
So I've prepared some data that I can share with you essentially trying to look at the market competitiveness on a county by county basis here.
As we do our national analysis, thought I would drill down here real quick since we have county level data.
But before we dive into that, I guess, you know, welcome to the group, Katie.
And of course, Heather is here. And then, Katie, you wouldn't mind introducing yourself if you want.
You don't have to, but just just curious.
What avenue you're coming at the group from.
Oh, it's okay. Always, always happy to have people listen.
So without further ado, I'll share with you some of the work that I've been working on and we can maybe even spearhead and do some new development.
Okay. So.
We've started.
As you can see, we've got a blank map here.
So we're just now starting to essentially try to populate data.
All the public cannabis data that we can scrounge up for each state.
So, of course, the states, many states here in the east, the Eastern seaboard.
As well as some here in the south.
Don't permit cannabis.
Neither some of them, neither medicinally nor recreationally, and then many states don't allow cannabis recreationally.
So we're going to be collecting all the data that the states provide on either and or recreational and or medicinal cannabis.
So, for example, Washington State, Oregon.
You still have medicinal programs as well as recreational programs.
So we'll try to track that data. Same for Colorado and then states like Oklahoma just have medicinal sales.
And then, you know, we've got Illinois, Michigan.
And then we'll we'll take a look at Maryland and we're looking at some of the northeastern states as well.
So Maine has some good public data.
We'll see if Massachusetts has any data.
And then, you know, some of the southern states do have medicinal markets.
So Florida has medicinal cannabis sales.
So we'll see if there's any data there.
And then, of course, we can't forget Alaska and Hawaii.
I think Hawaii has medicinal and then Alaska has.
They have permitted cannabis. I forget if it's recreational and or medicinal.
And then we may even look at a few other territories, essentially.
So Puerto Rico has some sort of permitted cannabis, I believe.
And then I was looking in their Guam has cannabis.
So they may be worth looking at as well.
So for now, we were going to drill down on Oklahoma.
And so a pardon that this map is small.
I'll be working to render this larger in the future.
And so that's Texas County, Oklahoma.
And so essentially, we'll want to look at a county by county level analysis.
And so one measure of market competitiveness that was brought up at the cannabis conference was,
OK, let's just look at the total number of licensees per capita.
So that could give you an idea if there are any markets that may be underserved.
So if there's a high number of licensees per county, then that county may be getting saturated.
Whereas if there's a low number of licensees per county, then that county may be ripe for
for trying to set up a new license.
Or there may be a reason for that.
There may be or there may be hard to do licensing in that county.
So there could be a variety of factors.
So what tools and data do we need?
Well, first, started to just go ahead and write.
So first, just posed our question.
So, OK, we're looking at licensees per capita in Oklahoma.
We would like to look at licensees per capita by county.
Of course, our null hypothesis is there's just an even distribution of licensees per state.
I mean, no one county has a statistically significant difference than another.
And we will reject this if we can conclude that any counties do have a statistically significant number of licensees than another.
So that's a research question.
So let's get to work.
So first things first, we need the number of licensees in Oklahoma.
I have Fortanlytics put together a script that collects data, public data, public cannabis data for Oklahoma.
And so this is MIT licensed so anybody can use it for any purpose they wish.
Just make sure to give a link back to Canlytics as the copyright holder.
However, this script essentially just collects data from various sources.
So we're not looking at revenue at the moment.
We're just looking at licensees.
So essentially, Oklahoma provides a running list here of licensees.
So essentially what the script does is, OK, just downloads all of these PDFs, parses this data into a usable format.
So there's the raw data.
And then you can use this script here and you can get a decent list of licensees in Oklahoma.
So now we know, OK, we've got the licensee, their trade name.
So a lot of companies may, not a lot, but a handful of companies may do business under a different name than their registered business, their licensed business name.
So, for example, here we've got a license that's licensed under Donald P. Northcutt.
However, they're going to be packaging as Big Bud.
So you're going to know them at the store as Big Bud.
So this is not uncommon in the cannabis industry.
Here's Toe, Oklahoma.
So just to say what anyone's doing per se, but a lot of times you may see it essentially to help with banking.
So it's still tough for cannabis businesses to get banked.
So these people could be doing things for different reasons.
However, it would probably be easier to get banked under agency properties versus Toe, Oklahoma.
And that's just the tragic nature of the state of affairs.
And so, OK, but to long story short, we have many companies here in Oklahoma.
So some include including every licensee that's plant touching in some way, you know, from waste disposal to laboratories to dispensaries to the growers themselves.
And of course, processors and the whole shebang.
There's almost 13,000 plant touching businesses in Oklahoma.
So where are they? Are they all right outside of Oklahoma City?
Are they all in the country?
So we know what city they're in. However, actually, we can even look at the zip code.
So I didn't even realize that we could get that granular.
So for this analysis, we'll just be looking at the county.
So we'll try to get a county by county count.
So without further ado,
let's try to do just that.
So it's just running quick Python script here.
OK, so essentially, we're just reading in the licensees data.
So this is the data we just saw in Excel.
So we can just do some sanity checks here.
For example, let's look at OK, what are all of the license types that we did in fact get?
So like we expected, we've got the growers, the labs, the waste disposals and dispensaries.
And we also have processors and transporters.
So you could find out how many of each there are.
So if you wanted to do that, which I mean, why not?
So I'm a little curious. OK, how many of each are there and what's the percent of the total?
Because we can do a little exploratory data analysis since this is the first real good time that I've had to look at the licensees data here.
So let's look at it together.
So the way I would do this is OK.
So let's look at each of these types.
So for the license type.
OK, so what do we want to do here?
So we want to isolate data for that type.
So let's just locate the licensees where the licensees license type.
Equal to the license type.
OK, not too bad.
And then what do we want to do?
Well, let's just print out some statistics here.
So one, a statistic is a total.
So so we could just say, OK, what's the total number of license type?
That's just going to be the total number that we just found.
And then I'm also curious, OK, what's that as a percentage of the total?
So let's just say.
OK, so what's that as a percent of the total?
Well, we're just going to be the length divided by all licensees.
Then I'm just going to add an extra space here just so things print out decently.
And then let's also maybe just format this decently.
So let's round this times 100 in two decimal places.
OK, so now the numbers look a little cleaner here.
OK, so this is interesting.
We can start to, you know, these would be good numbers for a pie chart here.
So that way you can actually see, OK, what are the pieces of the pie?
For now, we'll just look at the just the raw numbers.
So OK, so this is actually surprising.
So I knew it was going to be a high percentage.
For some reason, I was thinking higher, just my.
My. What do you call it?
My naive prior would have been higher.
However, it's about 70 percent of all licensees are growers.
About 12 percent are processors.
That's interesting. I would have thought higher, but about 12 percent.
That's about right. I would have thought about 20 percent, but.
That sounds about right.
Well, yeah, so maybe maybe that's more growers than I was expecting.
So you have about 12 percent processors.
Well, should we try to do a quick pie chart just for the heck of it?
Since since we're crunching numbers here and that's what we do.
So let's do a map plot live pie chart and see if it's not the hardest thing in the world.
Because if we can get a pie chart.
You know, thrown together.
You know, in a couple of minutes, then.
Also, I'm going to spin this down.
Yeah, I think we could look at some of this data here.
So let's let's look at a quick pie chart here.
So right, because we're already looping through this.
So all we have to do here is just collect these points that we're.
We're trying to do, right?
So we just have to collect the what's called what they're calling the sizes here.
So the size of each piece of the pie.
Right. So all we have to do.
Is keep track of the proportion.
Each license type makes up and look, we're already calculating the proportion.
So that's easy enough.
We don't really need to explode anything. In fact, we're trying to do the exact opposite.
And then it looks like.
They have their labels as a tuple, but we're going to try to do our labels as a list and see if that works.
No one caught me. We need to append these not.
OK.
So let's see if we can't make a quick pie chart just to get a bit better visualization.
OK. And look at that.
So now we can actually get the data.
So.
So we've got the growers.
Making up about 68 percent processors, 12 percent.
The dispensaries, about 18 percent.
So.
That's quite interesting.
About 30 percent here.
Processors, dispensaries.
And then look, just this tiny little sliver.
You have about one percent of.
So you have a very small number of these almost ancillary.
Plant touching businesses so that still make the.
Make the industry function at the end of the day. Right.
So you need transporters to get products from point A to point B.
In certain states like Oklahoma, you really need to pay attention to waste disposal.
So there's waste disposal companies and you need your your quality control.
So you've got the laboratories often doing the state mandated quality control tests.
So. So that's the breakdown of licensees.
Let's go ahead and move on.
You know, trying to get to bogged down in that.
So we've got our number of licensees.
And like let's not forget lose sight of what we're after here.
We're after the county by county breakdown.
OK, let's get a couple of data points before we continue.
So because we were trying to get the population.
So a quick aside.
The place you want to go if you want to get reliable.
Credible.
Economic data points for economic indicators such as population.
The place you want to go is the Federal Reserve and Fred.
So this is economic data repository.
Public open to the you know, it's free.
And you can use it via API, which is what we'll do here momentarily.
And.
This is a trusted data source, so no one will be too hard on you.
If you use the Fed Fred data, you know, of course, they may say, oh, why did you use, you know, the not seasonally adjusted series or this or that?
However, they won't you know, they won't try to undermine the data source itself. So so that's why it's credible and reliable.
So.
But in that regard, I would still hedge the data in that.
OK, the data is still probably not probably.
It is an estimate of the population here.
So, you know, it's probably not spot on to a T.
However, you know, we can get a decent.
Measure of the of the population here.
And so, for example.
Here we just have OK, here's just the total population in Oklahoma.
Times 1000, so this is thousands of people.
So.
Just shy of four million.
People in Oklahoma.
And then you can get this on a county by county level basis.
And so, for example, this is LaFleur County.
Has almost 50,000 people.
So.
So long story short, we can go ahead and get those data points just using the, you know, the Federal Reserve.
API.
So, you know, we can get the population.
Of Oklahoma.
And then we can actually get the licensees per capita.
So this number on itself may not be that.
Informative slash interesting.
However, what would be interesting would be to calculate this number licensees per capita.
For.
For all of the states that way we can see, OK, which states.
You know, how do the different states shake out?
So, for example.
Illinois, I think there's only, you know, a handful of dozen.
So, you know.
A couple dozen to maybe more licensees in the whole state.
And so if you think about the population of Illinois.
Then this number licensees per capita is going to be much smaller than it will be in Oklahoma.
And so the scale will be interesting.
So the scale there will be interesting.
So.
We can't.
Well, yeah, we can't do state to state yet.
So let's just let's look at county to county.
And so.
Basically, what I've done here is I've just gone ahead and gotten the federal reserve.
That Fred code here for looking up each county.
And so this will be the first time I've done this.
So long story short, let's try to look at the licensees per capita in each county.
And ambitiously, we may try to plot this.
It could be a wild one, but we're going to try.
OK, so.
Without further ado, let's start looping over these counties.
So so we'll just kind of view this on the fly, right?
So OK, so we want to do it for each county.
We know that.
So for county and counties.
Well, what do we want to do?
We want to find all the licensees in that county.
Then we want to get the population.
Of that county.
And then at that point, we just want to calculate the licensees per capita.
In that county.
And we want to keep track of this.
So.
I'm just going to create a dictionary here.
We've got a dictionary of states and because just heads up that I kind of know this is how I want the data presented here in a second.
So that's why I'm formatting it like this.
So so we then do licensees per capita.
OK, so first things first, we want all the licensees in that county.
So.
So the county licensees.
Oh, well, that'll be simple enough.
That's just going to be the licensees.
Where the licensees.
County.
Correct.
It's equal to that county.
Simple enough.
And we want to get the population of that county.
Well, we know how to get the fed spread data.
So we've got the county population.
And then we got the county code here.
That's right.
And I want to make sure this is equal equal to the county name.
Because we've built a good county.
I just call it pop graph.
So.
Long story short, we want to get this.
OK.
And then we would just want to calculate the licensees per capita in that county, which we did for the state. So we can use that same logic once again.
So this is just going to be county licensees per capita.
And that's just going to be.
County licensees.
Divided by the county population.
That's a thousand since these are in thousands of people.
Cool.
So we now should have that.
And then.
Basically, we want to keep track.
Of the data and the way I'm doing it is in the dictionary of county.
And then I actually want some variables here. And then basically I want to keep track of this as.
Licensees per capita.
That's how I'll keep track.
Of this data.
So.
That should work.
Let's just go ahead and.
Print some.
Print some data out here just so we can kind of see what we're doing as we're going. So we're just going to say OK.
OK, what's the county.
With the population of the county.
And.
What's.
The number of licensees.
And then finally, what is the number of licensees per capita.
So just go ahead and print that out for each county.
And.
I'm going to go ahead and just print a separating line here.
And let's see what happens.
We got an error and that's because I was not using this county name here. So let's just go ahead and define a new variable in the Pythonic way.
County name.
So simple enough.
And we are cranking out some calculations here.
Awesome.
So we just printed out.
Probably printed too many lines here.
We just.
I probably should have once again, print. Oh well, print county name. OK, so long story short, we've got our counties here.
We've got the population.
As of 2020. So keep in mind, this is the 2020 population. So all of these numbers are done with 2020 population.
So.
So we now have the number of licensees and then we also.
So, for example.
You can really start to compare these counties, right? And so this is where you may start to get a measure of competitiveness, right?
Because, OK, a DARE County has already issued 18 license, 118 licenses.
A TOCA County has issued 76 licenses.
However.
A TOCA may be slightly more saturated with licensees than a DARE.
Just, just, just slightly. And so, so this is where, OK, you may not necessarily just want to look at the total number of licensees issued per county.
But you may actually want to measure them.
Based on.
On licensees per capita.
So.
So we now have this data and so now we want to look at this data.
So there's two ways we can do this, the easy and the hard way.
So the easy way is just, if this just works with my JavaScript.
If this just works with my JavaScript map here, if not, we'll have to make a map in Python.
So I'm going to my try. Yes. So right now I just need to print.
Right now I just need to print the licensees per capita.
And then let's see if this data.
Just works nicely.
With
this Oklahoma County map that I've been tinkering with.
So
hopefully
this will be a bit of a problem.
Okay, not the end of the world here. So real quick like I just need to format.
The name where the spaces are replaced with underscores.
Sort of a pain here and I'm sorry Fred that I'm about to make a bunch of more API calls, but that's what we're going to do.
Okay.
But for some reason I don't think we'll have a chloro plant right out of the box.
Unless we're somehow able to.
Yeah.
Okay.
So I'll try to do this.
This could be interesting. So long story short, we're going to try to visualize this data.
Which is tricky right because it's state data, it's geographical data, but
we're going to try here. So long story short, we are trying to color this map.
So we're trying to color this with places with more licensees to be darker than the places with less license.
So going to show you a little bit of web programming here.
So we're going to just dump in our data just for the time being normally you would get your data from the server, you know.
Right. Normally you get that from your database. Okay, so we've got our data here.
What we can do is we can actually add a little tool tip.
Bear with me.
So okay, so the first thing first, let's just see if we can't just bought all this data here on the map.
Okay, cool. So now we can at least see the numbers.
However, we want to get them colored.
Also, I wonder if we can do something like, I forget what it is off the top of my head, but
I don't think it was that.
Well, this is what Google's for.
Oh, it's too fixed. Okay.
All right. And let's give it a few more decimal places here.
Awesome.
So now we have licensees per capita
by county in Oklahoma.
And so we've got 15 minutes left. Let's see if we can't color these.
So the
proper sometimes use a proper way and improper way to do things. So the proper way would be if somehow
we could
I wonder
if this variable is going to be accessible right here.
Doesn't look like it.
Interesting.
Okay, so we may have to resort.
Okay.
So the problem is, this is probably like much
smaller than number necessary to give us a good range.
Okay, so this may end up waiting to the future or we can maybe try a Python chloropleth real quick.
Just trying to scale this a bit.
Last shot here.
Hmm.
Okay, so we may not be able to get this JavaScript working right this second. So let's see if we can't.
I'm not confident that I can get a chloropleth going here in a in 10 minutes in Python.
Well, okay, here's the deal. We'll try it. We'll give it 10 minutes and see if we can't make a chloropleth of this data in Oklahoma in Python. And then if not, I'll finish this later.
I'll finish this plot later today and then post that link. So this is how you make a chloropleth in Python.
So
Well, it may not actually be as hard as one may think.
So let's see if we can use this handy dandy
package and do this work for us, right, because we're not trying to reinvent the wheel here. Okay, so let's see what this yields us.
Okay, do we just have our county names here?
Okay, those look like the Oklahoma counties. So that's cool.
We already have the licensees.
And so what was this chloropleth doing?
So let's just grab all of this.
And so we've got our county names, and we're just trying to make this chloropleth.
Okay, so we're, so it says, okay, so now we define the county shapes.
And let's hope these are defined already through BOKA.
It looks like they are. That's awesome.
Looks like we need a couple of BOKA's plotting tools.
That's okay with us.
Okay, so the main thing we need are values. That actually shouldn't be the hardest thing to do.
Maybe just partition our values.
So, you know,
let's just do it in the order that county names is in.
So we basically want to define our values here.
And so we'll want to just account for maybe just in case any of these counties don't have any.
So what we want to get licensees per county.
So we want to get the value for that county name.
If we don't find anything,
then we don't want it.
And this is just because this is how we,
well, how I formatted this data above.
Okay, actually, I'm going to need to just do something here.
Okay, so this just didn't work.
I may revisit this later.
Trying to do this on the quick. I think I can finish.
Okay, so we've got our licensees per capita.
And then let's just.
Let's just do this simple, right? That's sort of the Candlesticks model.
And I'm going to have to clean up all this code later.
Okay, so we've got a much more simple dictionary now, which is the county name value.
So that should make making these values much easier to get.
Right now, our value is just going to be licensees per capita.
Okay, much simpler.
So we've got all our values.
Okay, so this is the Oklahoma cannabis licensees per capita.
Well, let's see what happens.
We've got five minutes left to debug.
If anything goes askew.
And it's not held get the JavaScript up and running today.
So thanks for bearing with.
Thanks for bearing with as we went through this exploration here, but you saw us firsthand.
How we go about scrounging the licensees data, supplementing it with population data from the Federal Reserve.
Calculating licensees per capita.
And.
Ideally, providing a visualization here.
And we've got an obscure error that I'm not certain I can debug right here on the fly.
One can hope it's just some problem with these tooltips or something.
But.
So we unfortunately.
They don't think it's the value so there must be something.
What.
What is going so.
So let's just try to district.
Oh.
Probably because we don't have a plot.
That's so bizarre.
So.
So we may have to give it one shot here in spider just.
Just to see if there's something just going on with the plotting.
But otherwise, I may have to send it to.
The final output to you afterwards.
Just a little bit of a letdown because I was real curious to see this data and talk about it here.
Let's just do one quick Google search and then we may have to just.
Oh, that's right. So it gives us.
This HTML.
Hold on. We may just have a plot here.
That's bizarre.
We may just have a plot.
That would be bizarre if.
Well, by golly.
Something happened.
I don't think this is what we quite what we quite wanted. It was it. So this appears to be Oklahoma.
With with only some of the county shaded in.
And and so.
So long story short, going to need to touch this up a bit.
But what you can see right off the bat here.
So there's going to be a lot of cleanup that needs to be done. So thank you for bearing with this initial for a.
But this is I mean, this is interesting right off the bat.
So it's going to need to be cleaned up a bit.
But as you can see.
The counties that even permit. It looks like cannabis licensees are limited.
And so it looks like I want to get the actual numbers here and get the shaded in.
But surprisingly, it looks like a wide swath of the licensees are in this.
Eastern Crescent.
Here.
So.
So I apologize that these maps were.
Finicky and not behaving well. And so that's that's the thing with geographical data like it is.
A wrangling process to get these maps to work. And so I'm going to spend a bit of time today and get these cleaned up because this is a little embarrassing.
And so for next week, I can point you at.
I can point you to.
State data trove.
As we fill in state by state.
And so and hopefully county by county.
So it's going to be a little bit of a journey here getting all this data.
Processed and presentable.
However, we're on the right road.
So.
I did my best to present this data will will give it another go again next week.
So thanks for bearing with this ad hoc data presentation here.
And I'm going to go ahead and wrap it up there.
If there are any.
Questions I can field a couple of questions before concluding.
Yeah, I actually had a question.
By all means, so sorry about earlier. I was having trouble getting my microphone unblocked, but I'm pretty new to data science. I was just wondering why you decided to pick Python to examine your data.
Good question. That's sort of my tool of choice. So.
It's just what I'm most comfortable with. So I work with a couple people and they like to use our so that's their first go to choice. So for me.
I find it simple. It just generally reads like English. I find it powerful. Basically, I find if I want to do something with Python.
And it can be done on a computer. I can do it, which is awesome because then like you saw today.
The Oklahoma licensees data is in a bunch of PDFs. And so I found okay well that's on a computer. I would normally download this PDFs and put them into Excel by hand.
Manually with Python, I can download all those PDFs scrounge all the data, get it into Excel with the click of a button.
I'm sure you can do this with other programming languages. So I'm sure you could potentially do this with our.
You could definitely do this with C or.
Or who knows? I'm not well versed with programming languages that you know there could be Java or.
Potentially PHP, what have you. So it's to me I see them as tools, you know means to an end. So.
I just picked Python because I knew I could. Well, I didn't quite get the job done, but I knew I could get given more time I could get the job done. So I knew I could get the job done with Python.
So that's why I chose in. So does that answer your question? Yeah, for sure. Thank you.
How about yourself? Do you have any go to tools that you use for data science? So far, no.
I'm going through the Thinkful program at the moment and I finished with Excel and then I'm pretty close to finishing SQL, but I haven't started with the other ones yet.
OK, so the SQL will be OK. That's where OK, yes, we need to store our data in the database.
By myself, I'm not the biggest SQL expert. I a lot of the times use no SQL Firebase.
And so that's like the JSON like dictionary format formatted data for me. It's a bit more natural and.
I gravitate towards. So my recommendation, of course, I'm biased, but my recommendation would be what you may want to try to install Python and try to do a little bit.
Of course, try to figure out, OK, what are some of the repetitive tasks that you find yourself doing? Oh, I'm downloading this data set on every week or oh.
I keep searching for these journal articles or this or that and just find things that you do repeatedly and automate them.
And so you could set up what's called a cron job, so that's just have your Python script run automatically.
So you could have your Python script run every Monday and.
Get you data for the week, so. That's my personal recommendation.
Python's got a close place to my heart. So maybe maybe it'll find a place near your heart. Yeah, hopefully.
I think we're learning that next, so OK, well, my recommendation is.
Make it make it your own. So like a lot of times.
You know you get out of things which put into them, and so that's why I got so I learned Python in a.
Computational economics course and it was one of those things where I just fell in love with it and I realized, oh wow, I can make really cool plots with Python.
And so I just went out of my way to whenever I needed to make a good looking plot.
I would do it with Python, no matter how hard or arduous.
It was so. But it was worth it. It paid off because.
The cool thing is, once you write the code, you have it so.
Although it wasn't that clean rate, I was digging up this old.
Boca chloroplet chart that we had done months months ago, and so with a bit more tinkering, we could get it to work.
But long story short, you know you can and that's the that's the importance to writing clean code is so you can just pick it back up months later and use it.
That was not clean code could not pick it back up and use it. That was unfortunate.
So long story short, you can write these awesome tools for yourself, which will.
Be there for perpetuity and.
Sky's the limit, so that's my.
Promo for Python. Thank you.
Yes.
On that note, future Python East is I want to go ahead and wrap it up for today.
Just don't want to just.
Just stay, you know, just spread it too long, but.
Like I said, there's still more cleanup to be done here. So for next week we can have some real beautiful looking charts.
And so that's what I'll be tinkering on, but you can at least I think it's important to see the process because it's not like.
Just someone waves a magic wand or you know flashes their little curtain or what have you and then.
Yeah, so pleasure people don't just wave a wand and things are made there's there's tinkering to be done and there's mistakes to be made along the way.
And so, as you saw, we've got some ugly looking charts along the way we're making some mistakes.
We're we're figuring this out, but.
You'll see next week the sausage will hopefully we'll get some good visualizations out of it.
So that's the idea.
On that note.
Thank you both for attending for coming today and definitely feel free to reach out if you have anything you want specifically covered in in the coming weeks.
And then next week we'll be moving on to more states and just trying to fill in this map and get all the public cannabis data that we can and make it available.
All right, I'm going to end the recording here and see you both next week.