--- lang: ja-jp breaks: true --- # Python Google Drive上のCSVファイルを読み込む 2021-07-24 ```python= #%% import requests import io import pandas as pd import os from IPython.core.display import display scriptPath = os.path.dirname(os.path.abspath(__file__)) print('script path: ', scriptPath) csvname = "testdata.csv" csvpath = scriptPath + "/data/" + csvname csvpath_org = "https://drive.google.com/file/d/xxxxxxxx/view?usp=sharing" if os.path.exists(csvpath) == False : fileid = csvpath_org fileid = fileid.replace("https://drive.google.com/file/d/", "") fileid = fileid.replace("/view?usp=sharing", "") ## 以下のように書き換えます。 csv_url = "https://drive.google.com/uc?id=" + fileid display(csv_url) res = requests.get(csv_url) with open(csvpath, 'wb') as saveFile: saveFile.write(res.content) df = pd.read_csv(csvpath) display(df) ``` ###### tags: `Pandas` `Python` `Google Drive` `CSV`
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up