how to download zip file from google Drive to colab - google-colaboratory

I have shared link form google-drive and I need to downloaded into my colab
I use this code but it's not working
!gdown https://drive.google.com/file/d/1DAQsttkUzc8iPhQMeLNqssuTpzryCDL1/view?usp=sharing
this is the file
lian-v20.pdf

I believe that zip file already placed in your google drive.
Now if you want to access zip file from google drive to google colab then you have to mount your google drive to the google colab. Once you have have with mounting then write this piece of code in your google colab
from zipfile import ZipFile
with ZipFile('/content/drive/MyDrive/SHISHU==folder/Start/HELLO_TEST.zip', 'r')
as zipObj: # path where your zip file found
zipObj.extractall('/content/drive/MyDrive/TRAIN_SET') # path where you want to
extract your zip file and save

Related

Is there a way to get the ID of a Google Drive folder from the path using Colab?

Let's say I have a folder on GDrive with the path /content/drive/MyDrive/MyFolder. I know I can access the contents of the folder from Google Colab after mounting Drive. But is it also possible to access the ID/URL of this folder using Colab, and if so, how?
You can use kora to get ID from a file path.
!pip install kora
from kora.xattr import get_id
fid = get_id('/content/drive/MyDrive/Colab Notebooks')
# 0B0l6No313QAhRGVwY0FtQ3l1ckk

.ipynb file in Google Drive doesn't open with Colaboratory by default

I have two files in my Google Drive with .ipynb extension, but one of them is marked as Unknown File type and has a blue icon. What can I do to change the second one to a Colaboratory file?
If you want to get that icon you should save a copy from Colab
Upload your file to Drive
Open a file with Colab
Save a copy in Drive
Go to Drive and find folder
Inside you will find your file with the Colab icon

how to access a csv file which i saved in a colab project to another colab project

Help regarding colab project.
i am working on walmart sales prediction and i have created the required dataframe in a colab file, now for prediction of future sales i need to access that file and if i do that in the same colab file then the size being big the ram crashes... so i am thinking of accessing it in another colab file. How to do it and i dont want to download the file and upload it in that colab project.
df.to_csv('wm_sales.csv')
i have saved the file and its showing in my folder in colab and now i want to use it in another project.
You can simply mount your google drive disk and save any files in the specified directory:

How upload files to current working directory in Google Colab notebook?

I uploaded a Jupyter notebook to Google Colab. The notebook accessed a couple of images from local path /images/pic1.png How to upload data to the directory in Colab where the notebook is running? Please note that these are temporary files. So, I don't mind them being deleted on terminating the session.
I used Files upload feature but it doesn't seem to upload to Google Drive. I want to upload the folder with the same hierarchy as in the local environment without needing any change in the paths of the files in the code.
The better way I've found is mounting a folder in your Google Drive. Upload the image folder to your drive. After that, in your notebook you write:
from google.colab import drive
drive.mount('/content/drive')
After you allow the authentication, you can work using the path "/content/drive/My Drive" with the path for your image folder. Like that:
from IPython.display import Image
Image("/content/drive/My Drive/images/pic1.png")
See more in the notebook with documentation: https://colab.research.google.com/notebooks/io.ipynb

How to upload my dataset into Google Colab?

I have my dataset on my local device. Is there any way to upload this dataset into google colab directly.
Note:
I tried this code :
from google.colab import files
uploaded = files.upload()
But it loads file by file. I want to upload the whole dataset directly
Here's the workflow I used to upload a zip file and create a local data directory:
zip the file locally. Something like: $zip -r data.zip data
upload zip file of your data directory to colab using their (Google's) instructions.
from google.colab import files
uploaded = files.upload()
Once zip file is uploaded, perform the following operations:
import zipfile
import io
zf = zipfile.ZipFile(io.BytesIO(uploaded['data.zip']), "r")
zf.extractall()
Your data directory should now be in colab's working directory under a 'data' directory.
Zip or tar the files first, and then use tarfile or zipfile to unpack them.
Another way is to store all the dataset into a numpy object and upload to drive. There you can easily retrieve it. (zipping and unzipping also fine but I faced difficulty with it)