Hello and welcome to a video on saving files in Python. First, let's create some variables in our classdataS20
file. We'll go ahead and run this block of code. And you can see now we've
created some variables in our data frame. Now that I've created these variables, what if I want to save them as a different
file type? So let's go ahead and do that. First, we'll create a new save file path with
the name of the file that we'd like to save it as. And then you use a method called
to_excel to save the
file path using the file path that we've set up here. We're saying index false because we don't
want the index starting at zero right here, this index zero one two three four.
That's our index. We don't want that in our data frame that we're printing out.
Once I've saved that file path and run this line, it will go
ahead and create a file in Google Drive in the place of specified and it will be an Excel file
with our variables inside it. If you'd like to do the same thing but with the CSV, this
process is exactly the same except you use to_csv and in your
file path, you want to specify that it's a .csv instead of a .xlsx file.
Here are some other common file path types you may run across while working with data. We use JSONs for
APIs and data exchange. You might use two SQL if you're working with a SQL database table.
You may find yourself using to_pickle if you're working with Python objects and you may
use to_html if you're working on a website.