Accessing Files on Colab
Last updated
Last updated
There are two main methods to access data for Google Colab. First, you can upload a single file and work with it. Second, you can mount your Google Drive, and then you could access files similar to how you access files on your computer. This is best when you have multiple files.
Another option is to directly upload the files from your local machine into Google Colab. To do this, we import the files library from google.colab and use the upload function.
After you run the lines above, you should see the prompt.
Navigate to the file to choose that file to upload. Save all your course files to a single folder to make it easier to access later.
Second, let's connect your Google Drive to the Google Colab so you can upload files from your Google Drive folder to use. To do this, we import a library from google.colab and use the drive.mount function.
When you mount your Google Drive by running the lines above, you should receive a prompt to click on a link. Click the link and follow the instructions to allow Google Colab to access your Google drive. Make sure that it's the email address linked to the Google Drive that you plan to use for Colab.
Once you click the link and give Google Colab those permissions, you'll receive an authorization code. Input that authorization code into the prompt space.
The working directory is where the code will read and write files from. Check to see where your current working directory is using the !pwd
command. The "!" indicates that this is a command line function, and "pwd" returns the current working directory.
To change the working directory, you'll need to use the os package and the change directory function.
For more information about syntax, review the