# #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. As you see the data now, it's in dictionaries or list of tuples. And usually for a graph,
0:11 you want to have two dimensions, right? You want to have an X and a Y axis. So it's better to have two lists. One is the keys, and one is the values.
0:19 When I was preparing this notebook, I saw a great tip from Raymond Hettinger to use the zip, with star arguments, transposing to the data.
0:28 So this is exactly the kind of data we have. We have a list of tuples. And here, he's using a zip with a star on that data structure.
0:38 And he gets to transpose the data. And I'm going to use that too. Make our list of tuples, in an axis of keys, and a Y axis of values.
0:47 So let's write a transpose list of tuples, and takes data. And it's a little bit of type checking I had to do.
1:00 Because data can come in as a list of tuples. But it can also be a date. So, if it's date, then I make us as list of tuples.
1:08 I'm just making sure that all the data we're going to transpose is of the same structure. So dictionary should be a list of tuples.
1:16 And then I'm going to use Hettinger's trick to do transposed, list, zip, *data. And I'm going to return the new data. Let's see this connection.
1:40 How cool. So here we got the X axis, and here got the Y axis. And this is kind of format you want, to make it easy to plot.
1:49 Before going in to plot, one final thing, and you want probably read up the beginner documentation, plotly can be used in offline and online mode.
2:00 And for this tutorial, we are going to use it in offline mode. And there's a special switch to use this in my notebook.
2:07 I can set that all with one line of code. So I do plotly offline init. Notebook mode, connected equals true. And with that done,
2:20 we can start plotting in the next video.

Talk Python's Mastodon Michael Kennedy's Mastodon