[MUSIC] I'm sure you've all seen data presented in tables before. And now we've also seen several different ways in which we can store tabular data in Python. The question now becomes, where does that tabular data come from? I don't want to hard code it directly into my program and put it as a constant at the top, because I'd like to be able to analyze different data different times that I run my program. So we want to be able to read that data from files. We don't want to have to ask the user to input it all the time, we don't want it to be a constant in the program, we want to be able to read it from a file. So the question then becomes, what should that file look like? And that's where CSV files come in. CSV stands for comma separated values. And this allows us to store tabular data in a consistent way that allows us to read and write it from different programs, and be able to interpret it as tabular data. So, let's take a look at what this looks like. In order to talk about how we're going to store our tabular data in files, we actually need to have some tabular data. So, I have some here. And I have daughters, so I chose Information about Disney princess movies. And you can see here that I have the movie title, the year the movie is released, and the name of the princes in that particular movie. And I chose four out of the countless [LAUGH] Disney princess movies to put in my table. Now how are we going to store this? Well, we'd like to store this data in a way that we can easily use it for Python. Furthermore, we'd like to be able to use data that was produced by other programs, okay? Now conveniently, there is a format that is very widely recognized that allows me to store tabular data in plain text files, and that format is called CSV, and CSV stands for comma separated, Values. Okay, and the CSV format is very widely supported by lots of different programs that operate on tabular data. And one of the most common ways of creating tables, or entering tabular data, is to use a spreadsheet program. And all spreadsheet programs allow you to explore the data within them in this CSV format. And they might use their own proprietary format internally most of the time when you save your data, but if you'd like to use it somewhere else, you can export it as a CSV file. And you can also read it in as a CSV file, right? That solves the problem where one person is using Microsoft Excel on Windows, some other person is using Numbers on their Mac and maybe some crazy people, [LAUGH] like myself, use LibreOffice on Linux. All of us can type our data into our spreadsheet, export it as a CSV file, give it to each other and then we'll be able to read in each other's data. So we want to use the same format, so that we can read data produced by these other programs, and know there's a wide range of them. And read them into our phyton programs and process them. So, what does the CSV file format actually look like? Well, the name gives you a clue, comma separated values, well, values are separated by commas, right? Okay, but what does that mean? Well, each row in a table is a single line in the file, and then the columns within that row are actually separated by commas, okay? So let's take one row, let's say Tangled, okay? So in the file that row would look like this, Tangled, 2010, Rapunzel. All right, and then if we wanted to add another row, okay, it would be another line in the file, so the next line in the file we'll take Frozen, 2013, Elsa. Although, [LAUGH] if you've see in the movie, you know that Elsa's not really the main character, it's Anna, right? Well, [LAUGH] anyway, this is the basic idea, lines in the file are rows from the table, okay, and the columns within that row are separated by commas. Now there are a couple of things that can change here. Even though it's called CSV, the separators don't have to be commas. So you could take this comma here and make it something else, it could be a semicolon for instance, so I could have semicolon separated. But whatever I'm using to separate the columns within the file, I have to use the same character throughout the entire file. Now also you can imagine that I might have a value in one of the columns that actually includes a comma, or whatever I'm using as the field separator. And in that case, I want to be able to distinguish it from separating the field as just another character inside of that particular field. So, often you quote the strings inside the file. And so anything inside the double quotes that is one single column's worth of data. And so that would allow me to include commas in there if I wanted to. And again, just like I can change the comma character, there's nothing special about using the double quote character here as the quote, you can change that as well. But commonly, the fields are quoted with the double quote character, and the fields are separated with the comma character, and every line is a row in the table. And that's the basic idea behind the CSV format. It's fairly simple, it's easy to ready. You can just look at the file and understand what's going on. And it's in plain text, so it allows us to transfer data between different programs that are operating on tabular data. In this video, I introduced you to how we're going to store tabular data in files, so that we can easily operate on that data in Python. The CSV file format is widely used and readily understandable. When you look at a CSV file, you can easily see how the data in the file corresponds to a table. Each line in the file corresponds to a row from the table, and within that line, the columns from that row are separated by commas. Now, there are a few peculiarities in the CSV file format. In particular, you don't actually have to use commas to separate the columns. You can use any character. Also, you can quote the values for the columns, and this is especially useful if you need to have the separator character within one of the column values. And as I said, the CSV file format is widely used, so almost any program that operates on tabular data supports the use of the CSV file format. Now they may use a different format normally, but they can also read and write CSV files. Making it a good choice for us, as it will allow our Python programs to interoperate with these other programs, such as spreadsheets, that use tabular data. Now, you might also have learned a little bit about Disney princess movies in this video, right?