首页 > 解决方案 > 在datalab jupyter notebook中加载csv文件

问题描述

我正在使用足够大的数据集(2 GB)构建机器学习模型,该模型无法在我的本地机器上运行,因此我决定使用 google cloud datalab。我已经成功创建了 VM,但我找不到如何像在本地机器中那样导入数据(使用 pandas read_csv)。我的数据在谷歌驱动器中。有什么简单的方法可以用来解决这个问题。

标签: jupyter-notebookgoogle-cloud-datalab

解决方案


# Excute below code in a cell
from google.colab import drive
drive.mount('/mount_unique',force_remount=True)
# HERE YOU WILL BE ASKED TO navigate to an URL, click on it and copy the authentication token to clipboard
# Paste in the text box shown and enter.

# execute the below code to list directories on your google drive
from os import listdir
print(listdir('/mount_unique'))

# print(listdir('/mount_unique/My Drive')) #lists contents of your drive

import pandas as pd
pd.read_csv('/mount_unique/My Drive/<YOUR_DATA_FILE_PATH>')

推荐阅读