Pandas with Python 2.7 Part 8 - Standard Deviation
Key Takeaways
This video tutorial demonstrates how to calculate standard deviation using Pandas in Python 2.7 and how to plot multiple subplots using Matplotlib, including customizing the plots and sharing axes between subplots.
Full Transcript
what's going on everybody welcome to another Python and pandas tutorial video in this video what we're going to be doing is standard deviation uh along with since I was just showing you guys how to plot and we did come across an example where we needed multiple uh subplots where we were plotting say open high low close and volume where those two things are kind of a different scale volume versus the price um could be useful to plot on an another pane or another window in map plot lib this is called the subplot so I'm going to show you guys that and then also we're going to do standard deviation which is another um Panda kind of buil-in uh thing so with that let's go ahead and get started so we're not going to use axis 3D anymore so I'm just going to delete that and we'll come down here and delete all this stuff here and that should be good now what we're going to go ahead and do is what we can do is we can say DF and then for standard deviation we'll call it STD and uh we're going to say STD equals pd. rolling uncore STD and then we're going to say uh the first parameter that we put in here is what are we performing this on we're going to perform this on the closing price then the next parameter is uh how large of a rolling stdr we're going to do and so we're going to say 25 and then finally we have this Min periods and we're going to say that equals uh one so the next question somebody might ask is can we apply this minimum periods to the moving average well let's see so let's go ahead and copy this and paste that in there this way we don't have to sacrifice the first 100 values it'll still show uh the moving average for those values so we'll let that go and now STD there and that should be so first of all let's just see uh so let's go ahead and print DF head we'll save and run it and we come over here and one you know it still gives us 100 moving average now it's actually quite good because what it's going to do for us is instead of you know taking you know three values adding them together and dividing by 100 it takes the three values since they're less than um less than the 100 it will just do that many right so in this case we would say three right or even one it still does the average right which is not an average at all but anyway uh moving right along uh so we have the standard deviation uh was done for us so now what we're going to go ahead and do is we'll come down here and say we want to plot on multiple axes well the way we can do this with M plot lib is we just specify the axes so we're going to say ax1 equal PLT do subplot basically what we do with M plot live is as soon as you notify it about a plot it's going to plot on that new plot that you just notified it about so this is how we can not only use uh Panda's kind of intuitive plotting but also use some of the customization of Matt plot live and I'll show you what I mean in a minute so we're going to say ax1 equals uh plot a subplot we're going to say it's a 2X 1 by one and then we'll come down here and then we'll just say DF uh close. plot now normally after doing ax1 you would actually say ax1 plot and then we would say DF close like this if we were just doing regular map plot live stuff but we're going to do plot instead so we can use oops and we'll use our parameters there but we're going to do plot instead so we can use Panda's intuitive plug and then what we can do though is we can then specify ax2 and we going to say ax2 PLT do subplot again it's a 2X one by uh or it's a 2 by one and this will be plot Number two and then this one we're going to say DF um [Music] std. plot and then PLT Dosh so now we can plot this all up maybe I don't see my there it is okay so wait for it and here we go we have our standard deviation down here and then we have our actual um plot up here now couple things one uh we did not have um of course I just closed it um let's show two two of the things that were wrong here one we just have the index number down here it's just a number and then two uh the axes aren't tied to each other so if we zoom in on one doesn't zoom in on the other one so there's a couple things that we need to change so first of all on the definition of ax2 we're going to say share x equals ax1 so it's going to share the axes with this one and then also where we have the definition of right here for par dates we're going to say index call equals d a capital D don't forget it date now um when we go to do this we got rid of that for the 3D plotting but now when we go to plot it we get uh dates there thank you intuitive pandas you're two kind so now we actually have them and then also when we zoom in any specific spot it zooms in on both charts so we can see uh the numbers um lined up okay so now we' got standard deviation and then we've got the actual plotting and then also multiple um you know subplots and then now I can show you guys what it what this head space and all this stuff does so WID space uh we don't have any width so um that's not really going to do anything but head space that will do stuff so we can close up the difference make it huge or whatever you know so uh anyway so that's going to conclude this video just wanted to show you guys standard deviation as well as plotting multiple plots um while still using uh the intuitive plotting of pandas so if anybody has uh questions or comments feel free to leave them below as always thanks for watching thanks for all the support and subscriptions and until next time
Original Description
While we're lucky enough to have standard deviation built into a standard library module with Python 3+, Python 2.7 is not so lucky. That said, Pandas came along and offered a quick solution to that by offering not only Standard Deviation but also a few others that we'll be covering. The idea of standard deviation is to discern a general "deviation" from the norm or average that a certain data set might contain.
Sample code for the series: http://pythonprogramming.net/python-2-7-pandas-data-analysis/
Pandas tutorial series: https://www.youtube.com/playlist?list=PLQVvvaa0QuDfHt4XU7vTm22xDegR0v0fQ
http://seaofbtc.com
http://sentdex.com
http://hkinsley.com
https://twitter.com/sentdex
Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from sentdex · sentdex · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
Python Encryption Tutorial with PyCrypto
sentdex
Python's Logging Function
sentdex
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
wxPython Programming Tutorial 4: Panels
sentdex
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
wxPython Programming Tutorial 8: Custom Button Images
sentdex
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
Basic PHP Tutorial 12: Associative Array
sentdex
Basic PHP Tutorial 14: Foreach loop
sentdex
Basic PHP Tutorial 16: Include and Require
sentdex
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
Basic PHP Tutorial 4: Variables and Comments
sentdex
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
Basic PHP Tutorial 1: Intro to PHP
sentdex
Basic PHP Tutorial 3: HTML with PHP
sentdex
Basic PHP Tutorial 9: While Loop
sentdex
Basic PHP Tutorial 10: Switch Statement
sentdex
Basic PHP Tutorial 2: Print and Echo
sentdex
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
Basic PHP Tutorial 19: Finding words in strings
sentdex
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
Basic PHP Programming Tutorial 24: String similarity
sentdex
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
Sikuli Tutorial 1: Visually programming in python!
sentdex
Sikuli Tutorial 2: Program visually in python!
sentdex
Sikuli Tutorial 3: Program visually in python!
sentdex
3D Bar Charts in Python and Matplotlib
sentdex
3D Plane wire frame Graph Chart in Python
sentdex
Raspberry Pi Part 1 Introduction
sentdex
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
Raspberry Pi Part 11: Remote Desktop
sentdex
Twitter Analysis: How to rank a user's influence
sentdex
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex
More on: AI Workflow Automation
View skill →Related Reads
📰
📰
📰
📰
Stop Starting With AI Tools. Start With the Workflow.
Medium · AI
AI Can Deploy Your Infrastructure in Seconds. That’s Exactly What Worries Me.
Medium · AI
7 AI Freelance Services Clients Are Already Paying For
Medium · Data Science
7 AI Freelance Services Clients Are Already Paying For
Medium · Programming
🎓
Tutor Explanation
DeepCamp AI