#100DaysOfCode in Python Transcripts
Chapter: Days 37-39: Using CSV data
Lecture: Demo: Getting started with CSV processing
Login or
purchase this course
to watch this video and the rest of the course contents.
0:00
Alright let's create our little application for our demo that will let us work with the CSV data. I'm over here in the actual GitHub repository
0:10
and we're going to create our application here. Now I want to create a virtual environment in here before we get started
0:17
and maybe I'll even name it venv So, I'm going to go to that same folder in my terminal here and I'm going to run the command
0:27
to create the virtual environment before I open this in PyCharm. Alright. If you were going to continue working in the terminal here
0:33
and you wanted to say, run Python commands you would do this on Mac and that would activate it, and if you were on Windows you would just
0:42
say venv\scripts\activate.bat like that. Either way, I guess you would use backslashes wouldn't you? But, until you get started here
0:51
I'm not going to worry about this because I'm going to work in PyCharm and so if I throw this over here or on Windows or Linux
0:57
say file, open directory it'll open this up and I'll go ahead and let it add the GitHub root doesn't matter so much for you guys
1:04
but I'm going to of course check all the stuff in. Now, we can just go to our virtual environment and say let's just ignore this,
1:11
it doesn't really matter and we're just going to get started like we have been by creating a program.py this is going to be our little way to explore,
1:20
and this is going to be the top level thing that we want to work with. So, I'm just going to print out kind of the basic structure
1:28
of what we're going to do in terms of working with this data and then we'll actually go write the code to implement that.
1:35
So, I'm going to define a main method here and just for a minute I'm going to do the pass. We'll do this little structure that is very common in Python
1:43
that says only directly execute this code if it's being invoked directly, if it's being used as a library.
1:51
Don't run main just leave the other functions here. So this is the common pattern and we're going to print out a few things.
1:56
We'll print out a little header value. Alright, so weather research for Seattle 2014 to 2015 and we'll just put a blank line like that.
2:04
And then we're going to need to initialize the data. Spelling is hard that's why PyCharm can fix it for us. Okay, so that's going to be great
2:18
and once we get down here, we want to answer the questions. What, say, the hottest five days? And then we'll say to do show the days.
2:29
And we're going to do this for a couple of different ways. I'm going to come in here and I want to answer
2:33
the coldest five days and the wettest five days. So, this is our goal is to run basically answer these questions
2:46
and we're going to do that by reading that CSV file. Before we do, let's just really quickly run and make sure this works.
2:53
Hey, it tells us basically here are the days, but doesn't yet show them to us. So we're going to need to get the data.
3:00
Let me actually make a little folder to organize that here. I'll call this data. And into that data file, I'm going to drop
3:06
this thing we downloaded in the previous video. Drop that there. PyCharm will put it over in the right place and we can look. Does it look correct?
3:15
Yes. Apparently PyCharm can help out with CSV files. I don't really care. But I do care about what the header values are going to be.
3:23
We're going to work with that later. So maybe go ahead and copy that preemptively. Now, I think we're pretty much ready to write the code
3:32
that is going to read that file and then provide the data so we can answer these questions here.