‫In the last video, we created this bad boy here.
‫Now let's try and make something similar, but using our own data so we can practice a little bit of
‫data manipulation along with plotting and put some of our pandas and map plot lib skills together.
‫So what we'll do will format the price column first.
‫We'll get it into integer format because right now we don't want those dollar signs and columns and
‫comments.
‫We don't want those for when we're doing numerical operations.
‫So to do that, we'll go car sales and then we'll change the price column.
‫We need to access the string.
‫We saw this in the PANDAS section.
‫We'll go string, dot replace and now we want to pass in a little bit of regex here.
‫There we go.
‫So essentially all this is saying is get the dollar, sign the comma and the dot, which is here and
‫here and replace it.
‫And we're going to replace it with.
‫An empty string.
‫So we'll see what this does.
‫Car sales.
‫We need to add car sales there.
‫So let's see what it looks like now.
‫Okay, beautiful.
‫But we've got two extra zeros on the end, so we don't want that.
‫So we want to go remove last two zeros.
‫We got car sales.
‫Want to access the price column again.
‫We're going to reassign it to Carsales Price.
‫Again, it's still a string.
‫So if we have a look at this go here type just to exemplify what we're doing with the dot string.
‫Oh, it's a series.
‫Okay.
‫But that's all right.
‫Well, this is still a string, so that's where accessing it with the dot string method here.
‫Maybe if we go zero string, there we go.
‫So that's accessing this little one here and it's telling us that it's a string.
‫So that's why we have to access it as a string first with STR and now we want to remove the last two
‫using slicing.
‫Well, let's have a look at what car sales looks like here.
‫Oh, no, we've removed too many.
‫So what we can do is rerun it.
‫We're going to have to re-import our data frame to fix that little issue.
‫That's going to just reset it because remember, Jupiter cells are running in sequential mode.
‫So if we run this cell more than once, it's going to continually remove the last two digits of our
‫price column.
‫As long as we keep running this.
‫So we don't want that.
‫So now our price column is in the format that we want.
‫We're going to add a Saoudite column which will be similar to the PD date range.
‫Function that we used up here.
‫Paid date range.
‫So let's do that.
‫Data range one one.
‫We want to get past a date.
‫2020.
‫Number of periods.
‫So this is how many dates we want to add?
‫We've got periods here.
‫So that's a parameter.
‫So that's going to add this one.
‫We had 1000 periods, but we don't want that many for our car sales data frame.
‫We actually just want date period for each row here so we can do that by going periods equals LAN car
‫sales.
‫And then we'll check out car sales data frame again.
‫Beautiful.
‫So now we've got a sale date here, which is sequential.
‫That's okay.
‫Maybe they all weren't sold on sequential dates, but we're just making an example of how we can start
‫to manipulate our existing data frames.
‫So the next thing, what we want to do is we want to make a total column.
‫So we want to start to add up how much we've made from selling all our cars.
‫So if we added 4000 to 5000 to 7000.
‫So this is where we can use something like come some because it's going to add each of these prices
‫cumulatively.
‫So let's make a total column.
‫This should be car sales.
‫Total sales.
‫And then what do we want.
‫We want the price column.
‫That's right.
‫Car sales price.
‫Dot com.
‫Some.
‫Let's see what happens here.
‫Car sales.
‫What have we done?
‫It's worked.
‫But because the price column is still in string format, it's just concatenated the strings to each
‫other.
‫So let's have a look at our sales price.
‫Zero dot D type.
‫Oh, that's a bit boring.
‫Let's get it back to exemplifying that.
‫It's a string.
‫There we go.
‫So our price column is still a string.
‫So to fix this, we have to change it first into an integer and then call the come some function so
‫we can do dot as type.
‫Intercom some.
‫So what this is going to do is go reassign the total sales column to be the price column as an integer
‫as type int.
‫Dot cumulative sum.
‫This should work in theory, but as always, run the code.
‫Then check.
‫Beautiful.
‫Okay, so this has gone.
‫Total sales, 4000 plus 5000 is 9000 plus 7000 or 16,000.
‫And then it keeps going right up to the end.
‫So after we've sold all of our cars across these ten days or so, we have 76,450.
‫Beautiful.
‫That's some good profit there.
‫I can use that to fund our island.
‫Bought a store and now.
‫Let's plot the total sales.
‫So we want car sales.
‫We want to see what our total sales looks like over time.
‫So kind of replicating this graph here, but with our own data, car sales dot plot X equals sale date.
‫And now this is where you can call dot plot directly on a pandas data frame.
‫This is panda's version of the map plot lib API or the wrapper pandas wrapper for the map plot lib API.
‫So we're just going dataframe dot plot and we're passing it out x, which is the date and our Y, which
‫is the total sales column.
‫So let's see what this looks like.
‫Total sales.
‫And we'll put a semicolon at the end so it doesn't print out.
‫Beautiful.
‫There we go.
‫So this is just an example of how you can take.
‫Some code write from the documentation or some example that you found online and we've replicated it
‫up here.
‫But then we've taken the principles from it or some of them and put them together with our own data
‫and then created this little visualization here.
‫So now we can visualize.
‫Okay, so say we sold our ten cars over the first ten days of January.
‫Now our total sales is going up and to the right, which is very pleasing for our boss, because that's
‫the type of graph they want to see profits up into the right.
‫And so hopefully you're starting to get an idea of the kind of workflow that you can go about when you're
‫working on your own projects or working on problems you don't necessarily know the answer to.
‫It's all about searching up, trying to find some kind of example, taking information from that, and
‫then seeing if it works with your own problem.
‫Now we've seen a line plot.
‫How about we try a scatterplot?
‫So we've got car sales dot plot x.
‫Let's do it with the odometer this time.
‫Odometer column.
‫Cam Beautiful is at the right column.
‫Name?
‫Yep.
‫We've worked with this dataframe before, so we're kind of familiar with what's happening.
‫Price And then when you're calling the plot function, there's a little parameter here called kind,
‫which we can feed the type scatter to hopefully get a scatterplot here.
‫Well, what's happening.
‫Scatter requires y column to be numeric are is our price column not numeric.
‫It's still not numeric because here we've called as type int.
‫So this is only going to turn the price column into an integer for running this single line of code.
‫It's not going to reassign the price column to be an integer.
‫These are still strings in the car sales dataframe.
‫So what we can do to make this work?
‫We want to reassign the price column to be an integer price and equals car sales price as type int because
‫our prices are always going to be integers.
‫Money is a numerical value, so it's okay to reassign this data type to be integer.
‫This should work.
‫So we got.
‫Reassign price column to ENT.
‫Plot.
‫Scatterplot with price column as numeric.
‫So without this line of code, we'll comment that out.
‫We're going to get an error here.
‫Value error requires y column to be numeric, but what we're doing with this line here, if we uncomment
‫it.
‫To comment in uncomment code, we can do a command slash.
‫So I'm just pressing command slash here.
‫We're going to reassign it as a numeric column so we do this beautiful.
‫Now we have a scatterplot of our odometer column versus price.
‫And remember to remove this little piece of code here.
‫You can put a semicolon right at the end.
‫Excellent.
‫Now, I'm kind of saying a few examples here of how we can start to plot directly from a pandas data
‫frame.
‫We'll see a few more, but we'll end this video before it gets too long.
‫So in the meantime, before the next one, maybe you'll try plot a couple of these columns together,
‫whatever kind of plot you want to do.
‫You've seen a few a bar graph, a scatterplot, a line plot.
‫Have a practice of that and I'll see you in the next video.