 So now that we've got the CSV reader as you can imagine that's for reading files what if I want to write to a file and Well, we have the CSV writer and the entire idea is if you think about what the CSV Reader did is it would process each line as a list And so you got a nice little square brackets with each element separated by an index the same kind of concept comes in here with the writer I can come in here and Basically use a command called write row and if I pass it a list parameter then It'll write that up to the CSV file. So let's go ahead and see this in action So I am going to just come in and maybe I want to store the average Satosa data that I've been printing out so I'll come in and instead of printing it. I'm going to write it The other little bit here is I don't want to mess with my original data. So I am going to change the file I'm writing to a new file Here and so then it's just a simple writer equals CSV dot writer Now I can actually come in as you can see from the example That I was working off of I can tell it something like the delimiter and why not just to Show some of the functionality here I'm going to come in and I'm going to use the delimiter and for our sake. Why not? I'm going to use the Hashtag number sign pound I'm going to call it the waffle icon You can't stop me from doing that So anyways now that I've Created my object all I need to do is I need to write to my rows So I again want to store all of these average data points that I've just calculated into my right row So in this case, I'll come in writer Dot right row and as you can just see there was a right rows where you could have multiple Lists you can guess how that works In that case, I'll go ahead in I'm just going to add in Satosa as the first entry just because it's the Species that I'm working off of and then I'll just come in with the sepul length The sepul width pedal length And then the pedal width now I am starting to bleed over as you can see I'm hitting my nice little line here And this is just to say, you know, you've gone pretty, you know long on a single line. Perhaps you should consider Revising it. All right, that's fair enough. I'll go ahead and do that I'll come in right in between right about the middle Just nice little inner it should Sort of save itself the same kind of way. Now if I go ahead and hit run, I Don't see any errors. Fantastic. That's beautiful. And if I were to take a look inside of that that Data folder that I've just worked off of I should have a new calc iris Now it is gonna, you know, a spider will complain about this, but it's perfectly fine There's nothing wrong with this and what we should see is, you know, hey, there's the satosa. There's my waffle icon Then there's the sepul length the waffle icon the sepul width waffle icon sepul pedal length Hashtag pedal width Now as you can imagine No, I don't need to change it as you can imagine Just like we saw with reader. There was a dictionary reader variation Inside a python or inside of the CSV module. There is a dictionary writer as well There is one difference that has to go into working with the writer. However, in this case specifically you want to specify what Row or what order you want the elements to appear because again It's a dictionary so it's you can't just write them as is So in this case, all I would need to do is specify my field names or You know calls is what I'm calling them here, but they are known as field names inside of the CSV module I just specify them beforehand and then if I want them to appear inside of my my data I just use write header So let's see that in action again. I come in. All right. Well instead of it being a writer It'd be a dict writer Now again, I also do have to specify my my My field names and so I am going to cheat Because the first thing that we had done when we were dealing with the CSV file was print out the header name So yes, I am just gonna come in here and cheat I Can do that. That's my right Let's see. I'll go ahead and do it inside. That's perfectly fine field names It's also kind of bleeding over So I will go ahead and just do a nice little enter as well and so field names equals field names Now I can't use the right row as is and we'll see what I need to do in a second But I will come in and go with my right header And just to go ahead and see this run it and see what happens. I run it. No errors I go into my Calc Iris Yes Same kind of thing. Oh take a look at the order see pull length see with So everything's in the order that I just specified inside of my Field names now I should be able to build a dictionary and this is I like to Build the dictionary and then do the right. It kind of helps clean things up a little bit so I'll just call this to write In this case and I'll start with it being a blank dictionary To start actually I will go ahead and say that the species species is going to be Satosa the big thing here is it doesn't need to be in any particular order So now that I've got a base dictionary built. I will go ahead I'm actually going to use this as my my template of Boom Now I'm doing some you know just fast copy-pasting action here. That's perfectly fine. You know it comes time of practice but With this now I've gone ahead in and I'm just kind of hitting each one of them sequentially With the single character that I need to work on That I need to work off of and finally I'm able to come in with a quick copy and paste On those variables that we were just working off of So there it is the average sepal length the average sepal width the average petal length and the average petal width Now again the same kind of concept that was going on is when I'm working with this I Don't have to have it in a particular order. Let's say for example. I made my Petal width the first thing and then sepal length Last thing I specified a particular order that these field names should be appearing in so just because I put Satosa or species first doesn't mean that it's going to be written first It's going to be written where I told it to be written and so I save it Run it. I get no errors and when I take a look at calc iris It would help if you use the right row function so writer dots right Row to writes Always double-check your work because you never know you're going to do that. So now Still no errors hopefully. Yep, and then I'll come in I accidentally closed out of calc So yes, I care Now the one thing you are noticing is oh, it's coming in with these You know everything's going to be separated by a line And if I were to run this a second time you'd actually see that again. So just for that demonstration if I came in and Wrote that same line three times I run it You're seeing that it's separating everything by a line. Maybe you don't want that. Well, simply put We've already started to show how we're giving it different types of parameters I can actually add in one final one in this case. I'm going to call it new line equals blink the entire idea here is That the new line is as of right now the dictionary is writing That as in or sorry as is it's just also making sure that there's a new line character in there I don't want that Because as you can see it's putting things in multiple lines or spaced out with multiple lines This will say instead Don't do anything. Don't don't put anything at the end of this whatsoever. Take it. I run it What is it's a new line? I'm gonna do a quick Google, you know to see what that command was CSV new line It is not new line it is new line. Oh Derp instead of it being here with It should be up here And that's kind of just as a quick little bit That's a great example of when you should be googling is I knew that there was a new line I accidentally had it in the wrong spot So I double checked and I found a good little tip on. Oh, it's for open Now I take it. I run it and don't get any errors. I go to calc iris. Everything's on its own little line