简体   繁体   中英

How to upload and download a csv file to google drive using python?

can someone please help me. I need to know how to upload and download a csv file to google drive using python?

Using google collaborate .

First you need to mount your drive and define the PATH to the directory where you want to download or store your files.

from google.colab import drive

drive.mount('/content/drive/')
PATH = "/content/drive/My Drive/..."

Finally I suggest you to use pandas library to download or save the file.

import pandas as pd

#Download
df = pd.read_csv(f"{PATH}file_name.csv")

#Save
df.to_csv(f"{PATH}file_name.csv")

You can use the Google developer API to upload/download files to google Drive. This is the link to the help page with some code examples (dont forget you also have to enable the Google Drive API for you google account to be able to upload files.)

https://developers.google.com/drive/api/v3/manage-uploads#python

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM