1
00:00:00,000 --> 00:00:07,200
All right, in this lecture you'll learn
how to make time series graphs, so we're

2
00:00:07,200 --> 00:00:12,990
talking about data where one of the axes,
so normally the x-axis consists of dates

3
00:00:12,990 --> 00:00:16,949
or times, so let's say we have
temperature observations for several

4
00:00:16,949 --> 00:00:23,670
dates and we're going to have to plot
these values along the x and y axis.

5
00:00:23,670 --> 00:00:30,349
I've got some nice data here that…

6

11
00:00:45,550 --> 00:00:54,750
We're going to take from this link.
So it's a csv file.

7
00:00:54,810 --> 00:01:00,400
You don't have to download the CSV file
actually because we will be passing it

8
00:01:00,400 --> 00:01:07,180
as link directly to the read csv
method, so what we've got here is a date

9
00:01:07,180 --> 00:01:13,750
column and some other attributes. So you
may want to plot the data along the

10
00:01:13,750 --> 00:01:20,740
x-axis, and then the y-axis you want to
show one of these features. Let's say

11
00:01:20,740 --> 00:01:26,770
this attribute, close. So I'm going
to close this. I don't need this file

12
00:01:26,770 --> 00:01:36,310
because I'll use a direct link and let
me create the new cell, so I'll be using

13
00:01:36,310 --> 00:01:48,520
again the Bokeh.plotting interface
here and also import Pandas and the key here

14
00:01:48,520 --> 00:01:54,850
is that we will be using a Pandas data frame
and then we will parse this data time

15
00:01:54,850 --> 00:02:00,130
column as dates so that Python reads
them as dates and actually it's able to

16
00:02:00,130 --> 00:02:08,050
plot them in the x-axis, and I will be
using a line glyph to plot this data so

17
00:02:08,050 --> 00:02:13,960
a line glyph would be, you know you can use
circles, triangles etc., but you can also

18
00:02:13,960 --> 00:02:20,440
use lines. So you'd pass line here but
then the size doesn't make sense because

19
00:02:20,440 --> 00:02:30,960
you may want to pass the line width for
the line so not size but line width.

20
00:02:30,960 --> 00:02:37,720
And if you execute this, you don't see
circles anymore, so it's not a scatter

21
00:02:37,720 --> 00:02:44,190
plot now, but it's a line chart.
So we will use the same concept

22
00:02:44,190 --> 00:02:51,580
for building this date time graph, time
series graph. So first thing you want to

23
00:02:51,580 --> 00:03:03,290
do is load the CSV data inside Python.
So Pandas read CSV and you can pass

24
00:03:03,290 --> 00:03:11,360
actually the link, this link directly
to the CSV method.

25
00:03:14,060 --> 00:03:22,610
So how convenient is that? And then you
want to pass the parse dates parameter

26
00:03:22,610 --> 00:03:29,480
here, and you want to specify the name of
the column where these dates are, and the

27
00:03:29,480 --> 00:03:33,650
name of that column was dates so if you
remember from the CSV file that I opened

28
00:03:33,650 --> 00:03:39,950
earlier, that was date, and so once you
load the data frame object, you want to

29
00:03:39,950 --> 00:03:50,480
create a figure object. Let's say whidth
equals to 500 and height let's say

30
00:03:50,480 --> 00:03:57,500
500 for now, then we check how it goes
and we can change it later, so we have

31
00:03:57,500 --> 00:04:06,709
the x axis type parameter here, so what
this should do is, you want to make

32
00:04:06,709 --> 00:04:13,310
your axis, your x axis special so that it
can read date/time datatypes, and so to

33
00:04:13,310 --> 00:04:18,560
declare that you have date times, you
need to pass the data time argument

34
00:04:18,560 --> 00:04:25,370
as a string there, so that's it and then
what you want to do is apply the line

35
00:04:25,370 --> 00:04:32,810
object in there, so similar to this now
you need to pass the x axis and the y

36
00:04:32,810 --> 00:04:43,340
axis, so the x axis here should be df
date and the other axis is let's say

37
00:04:43,340 --> 00:04:52,400
close, so close column. Now let's make
the line Orange, and what else? Maybe a

38
00:04:52,400 --> 00:05:05,140
transparency of 0.5. Specify where you
want to save this, so under what name.

39
00:05:05,140 --> 00:05:17,419
HTML. Timeseries.HTML and lastly, show
the plot, and let's see. And something is not

40
00:05:17,419 --> 00:05:25,780
working, so Python is not being able to
pull out the data there. Ok, I need to

41
00:05:25,780 --> 00:05:34,830
pass the date here as a list actually, so
yeah, now it looks better, but it also

42
00:05:39,400 --> 00:05:48,030
looks a bit squeezed, so what you can
do here is you can change this to let's

43
00:05:48,030 --> 00:05:57,070
say 250 and you'll get a better graph
there. Now if you want to extend it to

44
00:05:57,070 --> 00:06:02,669
the entire page, there's something you can
do there, you can actually pass the

45
00:06:02,669 --> 00:06:15,090
responsive and set it to true. Let's see.
So you have, you get a bigger graph there.

46
00:06:15,090 --> 00:06:21,240
Of course you can zoom in to see some
details there.

47
00:06:21,240 --> 00:06:31,630
So for May 8th I have a value of 1 on
that date, you get the idea. So that

48
00:06:31,630 --> 00:06:36,000
concludes this lecture, and I'll see you
in the next one.

