Hi, welcome to this new video in our fifth week. So we're going to continue with the idea of how to write and read different file formats that we could use for, let's say, data visualization or for writing data that could be used for others. In this case we're going to be writing a table using CSV file structure. So a CSV file stands for a comma separated values. It's a file that understands using delimiter, which in this case is going to be the comma that we are actually in fact trying to construct a table, that has columns and rows, potentially, and this is an optional part of it might have a header, So as you can see here on the right, we have a table that has a header specifying we have the X coordinate, the Y coordinate, the Z coordinate, and then we have values that are for each one of those. The CSV file, as we can see on the bottom, really is very much like a text file, but we're using those commas with an intention, and we're going to see when we open a file like this, something like Google Sheets or Excel, that this file is going to be interpreted correctly as a table. So let's see how we can actually do that. We're going to use the same class, the createWriter("Data.csv"), and we're going to print lines in the same way. But in this case we're going to be combining variables and using the comma in between them to really construct something that could be understood as a CSV file. So we're definitely going to be working with that comma as a separator, the delimiter between values. So let's jump into the code and see what we can do here. So let's jump straight into processing. We're going to once again write a output , there's going to be a writer. We're going to call this data.csv this time. As simple as that, we will be creating a CSV file. Let's create a header. So output.printline. Here, our header, we have the value of x, y, red, green, blue. Notice that I'm adding commas to all those files. This is just a simple string, but I'm thinking of these values that are separated by commas just because the CSV file is going to be able to understand that. Let's imagine that what do we want to record? We want to record some variables, x and y are going to be float point variables. Red, green, and blue are going to be potentially integers. Let's do it for a series of maybe 500 objects. So for i in range 500, and we're going to create an x variable, it's going to be random.randrange between zero and 1200 which is going to be the size of our canvas. You can use this canvas variable. I'm going to try to think that what I'm doing is creating coordinates of let's say 500 random elements or circles in the screen. We have our module import random here available, so we can use the random function. Make sure that you have that as well. Down here, we're going to do the same thing for y. In this case we're going to use the random_height. Now, let's just do an r, this is going to start for red. Let's just copy paste this line once more. In this case we will have a value, but it's a random value between zero and 255. That's for a random red channel color. We can do the same thing for two more times for R, G, and B. So everything is random at this point. If we would like to see graphically, we can use fill for r, g,b so that we have a visual representation of what we are doing. So we can do an ellipse in the coordinates x, y, 20, 20. But what we're actually trying to do is write all this information to our file. We've seen this in previous videos. We can actually use random variables to construct 500 random spheres or circle. Often the data that we will obtain from outside might not be random. So it's going to be probably a lot more interesting data than the one that we're creating here. But we're learning how to write first a file, and then we're going to learn how to read it. Here's where it could actually get tricky, where we actually do output.printline. This line we want to convert to a string, the variable x. Then we want to add to that a comma. Then we want to repeat this sequence for all the different variables we have. We could do that side by side like this and do it for y. Some people really like seeing it a little bit like this. So we have y, we have r, g, and b. So I really invited you to format your documents in the way that are the most readable for you, RGB. I sometimes sacrifice the amount of space the code might take. There we go. We're closing that line. So that's the same print line as if we had everything in sequence. We're just making sure that we are adding the value as a string with the comma for x, y, r, G, b and so on. So that is it for the output. Then we should be within the loop here. Notice that in order to close the document, what we have done before, which is output.flush, and output.close, I need to get out of the loop. You don't want to be doing the closing of the document within the loop, and this might be a simple mistake because you're still within the indentation. So make sure that you don't keep these two lines indented, therefore they exit the loop, and we the document at the end. I also want to make sure that we do have a background because we're drawing these ellipses in the screen. Let's just do a background here, a black background. So we're not doing the draw loop right now, we're just drawing 500 circles in the screen at random locations. That's fine. That work. We can see them and we should have in this point a CSV file. So I'm going to go into a text or a Google Sheets document where we can open, let's just drag and drop that CSV file. Once you load a CSV file, you'll see what you have here. What we have is first, it's going to be our header row that contains the x, y. Basically what we described in this line up here. This line became the first line of our file, and as we continue printing the values here Google Sheets automatically can understand the CSV file to be a comma separated values. Comma separated value, meaning that these units end up in their own individual cells. So we have data that could be perfectly suitable for something like visualizing this data if we wanted to reconstruct the drawing from this data. Or maybe start doing like a scatter plot or any form of data visualization that we might think might be useful for this data. Coming to a file like this has a lot of clarity of these are x, y coordinates and these are the color values that are associated with those. With this we're going to leave it here and we're going to be looking at how to read this file in the next video. I'll see you there.