Plotting a DataFrame – Real Python (original) (raw)

This is the last lesson of the course and shows you how you can plot your final DataFrame using vincent.

Resources

00:01 We’re going to create a stacked graph, which is going to be represented by vincent.StackedBar(), which takes a DataFrame, which in our case is the field_goal_per_team.

00:11 We’re then going to create a legend for this

00:16 particular one, which is going to be a title, and it’s going to be "Field Goals".

00:27 Once we have that together, we’re then going to scale our _x_-axis so it’s spaced out cleanly. I only know this because I’ve done this before. It’s usually something you have to see with your particular dataset to figure out what looks nice, so this is mostly trial and error, but I know that works well for the particular

00:50 set that I’m working with. And then we’re going to simply go stacked.display().

00:58 So as you can see, we have a breakdown of each team, how Kevin Durant performed against each team in terms of field goals attempted and field goals. So as you can see, the field goals he scores are much less than the ones he attempted.

01:10 So he attempted about 40 and he scored about 20 of those against Atlanta. As you could see from before, that is about right. Where are you? He attempted 40, he scored about 20, which is quite awesome.

01:25 So you can see he doesn’t perform very well against Milwaukee. That could have been for various reasons, it could have been because he was injured or did not get that much playtime.

01:33 If you were to have another dataset of whether his injuries had occurred, you can easily show games where he’s injured or he was hurt the previous game or sick—you could see how his performance varies against those days.

01:46 And this is very much more consumable than anything else, and you can share this with friends and whatnot. This concludes our more in-depth talk on DataFrames.