Google ColabolatoryとGoogle Driveでデータをやり取りする方法
/ 1 min read
Table of Contents
はじめに
Google Colabolatory と Google Drive のデータ連携について、Pandas の read_csv と to_csv を例に書いてみます。
方法
事前準備
Googleドライブをマウントします。
from google.colab import drivedrive.mount('/content/drive')
Google Drive 上のファイルを読み込む場合
import pandas as pd
df = pd.read_csv('/content/drive/My Drive/hoge/fuga.csv')
Google Drive へデータを書き出す場合
import pandas as pd
base_dir = '/content/drive/My Drive/hoge/'file_name = 'fuga.csv'file_path = base_dir + file_namedf.to_csv(file_path)