How to save Google sheet created/updated in Python to the specific folder?

Viewed 150

I have this code:

from google.colab import auth
auth.authenticate_user()
import gspread
from oauth2client.client import GoogleCredentials as GC

gc = gspread.authorize(creds)

from gspread_dataframe import set_with_dataframe
title = 'Sheet_name'
gc.create(title)
sheet = gc.open(title).sheet1
set_with_dataframe(sheet, aa)

It works but I have problem, I can't save it into specific folder. It is always saved in the main folder

For exmple I would like to save it to folder:

/content/drive/My Drive/My sheets

Could you help me how to do this, please?

I tried to add pretext to "say" where I wan't to save this folder but it didn't works.

1 Answers

I thought that in your script, an argument of folder_id can be used. When this is reflected in your script, it becomes as follows.

In this case, please retrieve the folder ID from the folder of "My sheets" in your Google Drive. The folder ID is ### of https://drive.google.com/drive/folders/###.

From:

gc.create(title)

To:

folder_id = '###' # Please set the folder ID of "My sheets" folder.
gc.create(title, folder_id)

or

folder_id = '###' # Please set the folder ID of "My sheets" folder.
gc.create(title, folder_id=folder_id)

Reference:

Related