Google DriveでPythonの実行環境を整える方法をまとめてみた

Google Colaboratoryを使えば、Google Drive上でPythonの実行環境(Jupyter Notebook)を整えられるようなので、試してみました。

1. Google Driveにアクセスする

Google Driveにアクセスします。

2. Google ColaboratoryをGoogle Drive上で使えるようにする

デフォルトではPythonを実行できる、Colaboratoryというツールがないので、インストールします。新規 -> その他 -> アプリを追加を選択し、「Colaboratory」と検索します。そうするとアプリが出るので、「接続」をクリックすると、Colaboratoryを使えるようになります。


3. Google Colaboratoryを設定する

さっそく使ってみましょう。新規 -> その他 -> Colaboratoryを設定すると、新規でPythonの実行環境が使えるようになります。

試しに、タイタニックのデータセットをインポートしてみた結果をGoogle Drive上でPythonを実行してみました。その時のJupyter Notebookはこちら。

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

%matplotlib inline

# Titanicのデータセットのインポート

df = sns.load_dataset('titanic')
print(df)
> 

     survived  pclass     sex   age  sibsp  parch      fare embarked   class  \
0           0       3    male  22.0      1      0    7.2500        S   Third   
1           1       1  female  38.0      1      0   71.2833        C   First   
2           1       3  female  26.0      0      0    7.9250        S   Third   
3           1       1  female  35.0      1      0   53.1000        S   First   
4           0       3    male  35.0      0      0    8.0500        S   Third   
5           0       3    male   NaN      0      0    8.4583        Q   Third   
6           0       1    male  54.0      0      0   51.8625        S   First   
7           0       3    male   2.0      3      1   21.0750        S   Third   
8           1       3  female  27.0      0      2   11.1333        S   Third   
9           1       2  female  14.0      1      0   30.0708        C  Second   
10          1       3  female   4.0      1      1   16.7000        S   Third   
11          1       1  female  58.0      0      0   26.5500        S   First   
12          0       3    male  20.0      0      0    8.0500        S   Third   
13          0       3    male  39.0      1      5   31.2750        S   Third   
14          0       3  female  14.0      0      0    7.8542        S   Third   
15          1       2  female  55.0      0      0   16.0000        S  Second   
16          0       3    male   2.0      4      1   29.1250        Q   Third   
17          1       2    male   NaN      0      0   13.0000        S  Second   
18          0       3  female  31.0      1      0   18.0000        S   Third   
19          1       3  female   NaN      0      0    7.2250        C   Third   
20          0       2    male  35.0      0      0   26.0000        S  Second   
21          1       2    male  34.0      0      0   13.0000        S  Second   
22          1       3  female  15.0      0      0    8.0292        Q   Third   
23          1       1    male  28.0      0      0   35.5000        S   First   
24          0       3  female   8.0      3      1   21.0750        S   Third   
25          1       3  female  38.0      1      5   31.3875        S   Third   
26          0       3    male   NaN      0      0    7.2250        C   Third   
27          0       1    male  19.0      3      2  263.0000        S   First   
28          1       3  female   NaN      0      0    7.8792        Q   Third   
29          0       3    male   NaN      0      0    7.8958        S   Third   
..        ...     ...     ...   ...    ...    ...       ...      ...     ...   
861         0       2    male  21.0      1      0   11.5000        S  Second   
862         1       1  female  48.0      0      0   25.9292        S   First   
863         0       3  female   NaN      8      2   69.5500        S   Third   
864         0       2    male  24.0      0      0   13.0000        S  Second   
865         1       2  female  42.0      0      0   13.0000        S  Second   
866         1       2  female  27.0      1      0   13.8583        C  Second   
867         0       1    male  31.0      0      0   50.4958        S   First   
868         0       3    male   NaN      0      0    9.5000        S   Third   
869         1       3    male   4.0      1      1   11.1333        S   Third   
870         0       3    male  26.0      0      0    7.8958        S   Third   
871         1       1  female  47.0      1      1   52.5542        S   First   
872         0       1    male  33.0      0      0    5.0000        S   First   
873         0       3    male  47.0      0      0    9.0000        S   Third   
874         1       2  female  28.0      1      0   24.0000        C  Second   
875         1       3  female  15.0      0      0    7.2250        C   Third   
876         0       3    male  20.0      0      0    9.8458        S   Third   
877         0       3    male  19.0      0      0    7.8958        S   Third   
878         0       3    male   NaN      0      0    7.8958        S   Third   
879         1       1  female  56.0      0      1   83.1583        C   First   
880         1       2  female  25.0      0      1   26.0000        S  Second   
881         0       3    male  33.0      0      0    7.8958        S   Third   
882         0       3  female  22.0      0      0   10.5167        S   Third   
883         0       2    male  28.0      0      0   10.5000        S  Second   
884         0       3    male  25.0      0      0    7.0500        S   Third   
885         0       3  female  39.0      0      5   29.1250        Q   Third   
886         0       2    male  27.0      0      0   13.0000        S  Second   
887         1       1  female  19.0      0      0   30.0000        S   First   
888         0       3  female   NaN      1      2   23.4500        S   Third   
889         1       1    male  26.0      0      0   30.0000        C   First   
890         0       3    male  32.0      0      0    7.7500        Q   Third   

       who  adult_male deck  embark_town alive  alone  
0      man        True  NaN  Southampton    no  False  
1    woman       False    C    Cherbourg   yes  False  
2    woman       False  NaN  Southampton   yes   True  
3    woman       False    C  Southampton   yes  False  
4      man        True  NaN  Southampton    no   True  
5      man        True  NaN   Queenstown    no   True  
6      man        True    E  Southampton    no   True  
7    child       False  NaN  Southampton    no  False  
8    woman       False  NaN  Southampton   yes  False  
9    child       False  NaN    Cherbourg   yes  False  
10   child       False    G  Southampton   yes  False  
11   woman       False    C  Southampton   yes   True  
12     man        True  NaN  Southampton    no   True  
13     man        True  NaN  Southampton    no  False  
14   child       False  NaN  Southampton    no   True  
15   woman       False  NaN  Southampton   yes   True  
16   child       False  NaN   Queenstown    no  False  
17     man        True  NaN  Southampton   yes   True  
18   woman       False  NaN  Southampton    no  False  
19   woman       False  NaN    Cherbourg   yes   True  
20     man        True  NaN  Southampton    no   True  
21     man        True    D  Southampton   yes   True  
22   child       False  NaN   Queenstown   yes   True  
23     man        True    A  Southampton   yes   True  
24   child       False  NaN  Southampton    no  False  
25   woman       False  NaN  Southampton   yes  False  
26     man        True  NaN    Cherbourg    no   True  
27     man        True    C  Southampton    no  False  
28   woman       False  NaN   Queenstown   yes   True  
29     man        True  NaN  Southampton    no   True  
..     ...         ...  ...          ...   ...    ...  
861    man        True  NaN  Southampton    no  False  
862  woman       False    D  Southampton   yes   True  
863  woman       False  NaN  Southampton    no  False  
864    man        True  NaN  Southampton    no   True  
865  woman       False  NaN  Southampton   yes   True  
866  woman       False  NaN    Cherbourg   yes  False  
867    man        True    A  Southampton    no   True  
868    man        True  NaN  Southampton    no   True  
869  child       False  NaN  Southampton   yes  False  
870    man        True  NaN  Southampton    no   True  
871  woman       False    D  Southampton   yes  False  
872    man        True    B  Southampton    no   True  
873    man        True  NaN  Southampton    no   True  
874  woman       False  NaN    Cherbourg   yes  False  
875  child       False  NaN    Cherbourg   yes   True  
876    man        True  NaN  Southampton    no   True  
877    man        True  NaN  Southampton    no   True  
878    man        True  NaN  Southampton    no   True  
879  woman       False    C    Cherbourg   yes  False  
880  woman       False  NaN  Southampton   yes  False  
881    man        True  NaN  Southampton    no   True  
882  woman       False  NaN  Southampton    no   True  
883    man        True  NaN  Southampton    no   True  
884    man        True  NaN  Southampton    no   True  
885  woman       False  NaN   Queenstown    no  False  
886    man        True  NaN  Southampton    no   True  
887  woman       False    B  Southampton   yes   True  
888  woman       False  NaN  Southampton    no  False  
889    man        True    C    Cherbourg   yes   True  
890    man        True  NaN   Queenstown    no   True  

[891 rows x 15 columns]

普通に実行できました。勉強会とかで軽く実行するときとか、とても使えそうな感じがしますね。

まとめ

ということでまとめです。

・Google Drive上でPythonが実行できる
・Google Colaboratoryをインストールして、実行できる
・Web上で完結するので、簡単

ツイッターのフォローもぜひお願いします!


この記事が気に入ったら、サポートをしてみませんか?気軽にクリエイターを支援できます。

note.user.nickname || note.user.urlname

サポートでいただいたお金はFanzaの動画を購入するために利用されます。

うれしいです!ぜひ感想を#DAINOTE とツイッターでお願いします!
102

Dai

参考

6つのマガジンに含まれています
コメントを投稿するには、 ログイン または 会員登録 をする必要があります。