#100DaysOfCode in Python Transcripts
Chapter: Days 82-84: Data visualization with Plotly
Lecture: Prep 3: transpose data and init Plotly
0:00 There's still one extra step to take.
0:03 As you see the data now,
0:04 it's in dictionaries or list of tuples.
0:08 And usually for a graph,
0:10 you want to have two dimensions, right?
0:12 You want to have an X and a Y axis.
0:14 So it's better to have two lists.
0:16 One is the keys,
0:17 and one is the values.
0:18 When I was preparing this notebook,
0:20 I saw a great tip from Raymond Hettinger to use the zip,
0:24 with star arguments,
0:25 transposing to the data.
0:27 So this is exactly the kind of data we have.
0:29 We have a list of tuples.
0:32 And here, he's using a zip with a star
0:35 on that data structure.
0:37 And he gets to transpose the data.
0:39 And I'm going to use that too.
0:41 Make our list of tuples,
0:42 in an axis of keys,
0:44 and a Y axis of values.
0:46 So let's write a transpose
0:50 list of tuples,
0:53 and takes data.
0:56 And it's a little bit of type checking I had to do.
0:59 Because data can come in as a list of tuples.
1:02 But it can also be a date.
1:03 So, if it's date,
1:04 then I make us as list of tuples.
1:07 I'm just making sure that all the data
1:08 we're going to transpose is of the same structure.
1:11 So dictionary should be a list of tuples.
1:15 And then I'm going to use Hettinger's trick
1:17 to do transposed, list,
1:20 zip, *data.
1:27 And I'm going to return the new data.
1:30 Let's see this connection.
1:39 How cool. So here we got the X axis,
1:42 and here got the Y axis.
1:44 And this is kind of format you want,
1:46 to make it easy to plot.
1:48 Before going in to plot, one final thing,
1:51 and you want probably read up the beginner documentation,
1:55 plotly can be used in offline and online mode.
1:59 And for this tutorial,
2:00 we are going to use it in offline mode.
2:03 And there's a special switch
2:04 to use this in my notebook.
2:06 I can set that all with one line of code.
2:09 So I do plotly offline init.
2:12 Notebook mode, connected equals true.
2:18 And with that done,
2:19 we can start plotting in the next video.