Pandas with Python 2.7 Part 8 - Standard Deviation

sentdex · Beginner ·🛠️ AI Tools & Apps ·11y ago

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 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

This video teaches how to calculate standard deviation using Pandas and how to plot multiple subplots using Matplotlib, including customizing the plots and sharing axes between subplots. The tutorial covers the use of rolling standard deviation, min periods, and moving average, and demonstrates how to use Pandas' intuitive plotting and Matplotlib's customization options.

Key Takeaways
  1. Import necessary libraries
  2. Load data into a Pandas DataFrame
  3. Calculate standard deviation using Pandas
  4. Plot multiple subplots using Matplotlib
  5. Customize plots and share axes between subplots
💡 Pandas provides an easy-to-use interface for calculating standard deviation, and Matplotlib offers customization options for plotting multiple subplots, including sharing axes between subplots.

Related Reads

📰
Stop Starting With AI Tools. Start With the Workflow.
Rethink your approach to AI adoption by focusing on workflow clarity over tool accumulation, to maximize efficiency and effectiveness
Medium · AI
📰
AI Can Deploy Your Infrastructure in Seconds. That’s Exactly What Worries Me.
Learn how AI can deploy infrastructure in seconds and the concerns it raises, with steps to understand and mitigate potential risks
Medium · AI
📰
7 AI Freelance Services Clients Are Already Paying For
Learn about 7 AI freelance services in demand, from content generation to data analysis, and how to offer them to clients
Medium · Data Science
📰
7 AI Freelance Services Clients Are Already Paying For
Learn about 7 AI freelance services in demand, from content generation to data analysis, and how to offer them to clients
Medium · Programming
Up next
How I Use AI to Write Facebook Ad Scripts That Actually Scale
Nick Theriot
Watch →