<p>您可以将所有数据放入google驱动器,然后挂载驱动器。我就是这样做的。让我分步骤解释。</p>
<p><strong>步骤1:</strong>
把你的数据传输到你的谷歌硬盘。</p>
<p><strong>第2步:</strong>
运行以下代码装载您的google驱动器。</p>
<pre><code># Install a Drive FUSE wrapper.
# https://github.com/astrada/google-drive-ocamlfuse
!apt-get install -y -qq software-properties-common python-software-properties module-init-tools
!add-apt-repository -y ppa:alessandro-strada/ppa 2>&1 > /dev/null
!apt-get update -qq 2>&1 > /dev/null
!apt-get -y install -qq google-drive-ocamlfuse fuse
# Generate auth tokens for Colab
from google.colab import auth
auth.authenticate_user()
# Generate creds for the Drive FUSE library.
from oauth2client.client import GoogleCredentials
creds = GoogleCredentials.get_application_default()
import getpass
!google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret} < /dev/null 2>&1 | grep URL
vcode = getpass.getpass()
!echo {vcode} | google-drive-ocamlfuse -headless -id={creds.client_id} -secret={creds.client_secret}
# Create a directory and mount Google Drive using that directory.
!mkdir -p My Drive
!google-drive-ocamlfuse My Drive
!ls My Drive/
# Create a file in Drive.
!echo "This newly created file will appear in your Drive file list." > My Drive/created.txt
</code></pre>
<p><strong>第3步:</strong>
运行下面的代码行,检查是否可以在安装的驱动器中看到所需的数据。</p>
<pre><code>!ls Drive
</code></pre>
<p><strong>第4步:</strong></p>
<p>现在将数据加载到numpy数组中,如下所示。我有我的exel档案,有我的火车和简历以及测试数据。</p>
<pre><code>train_data = pd.read_excel(r'Drive/train.xlsx')
test = pd.read_excel(r'Drive/test.xlsx')
cv= pd.read_excel(r'Drive/cv.xlsx')
</code></pre>
<p>希望能有所帮助。</p>
<p><strong>编辑</strong></p>
<p>要从colab笔记本环境将数据下载到驱动器中,可以运行以下代码。</p>
<pre><code># Install the PyDrive wrapper & import libraries.
# This only needs to be done once in a notebook.
!pip install -U -q PyDrive
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials
# Authenticate and create the PyDrive client.
# This only needs to be done once in a notebook.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)
# Create & upload a file.
uploaded = drive.CreateFile({'data.xlsx': 'data.xlsx'})
uploaded.SetContentFile('data.xlsx')
uploaded.Upload()
print('Uploaded file with ID {}'.format(uploaded.get('id')))
</code></pre>