【问题标题】:Read csv to sframe in google colab在 google colab 中读取 csv 到 sframe
【发布时间】:2023-04-02 01:05:01
【问题描述】:

我在 google-colaboratory 上创建了一个新的 python 2 笔记本并安装了 sframe(!pip install sframe),但我无法读取 sframe 中的 CSV 文件。 有什么帮助吗?

【问题讨论】:

  • 你有什么尝试吗?你有任何具体的错误信息吗?请为您的问题提供更多详细信息 - 这将更容易回答!

标签: python-2.7 export-to-csv graphlab google-colaboratory sframe


【解决方案1】:

要在 SFrame 中读取 CSV 文件,您需要下载 turicreate 模块或 GraphLab create 模块。

首先,您需要将数据导入colab。所以你需要知道你是如何访问你的文件的:本地存储或谷歌驱动器。您可以使用此链接来实现此目的:Import data into Google Colaboratory

要在 google-colaboratory 中下载 turicreate 模块,请执行以下步骤:

1) 在 colab 中使用 pip 安装 turicreate 模块。

        !pip install turicreate

2) 导入 turicreate 模块。

        import turicreate

3) 使用 turicreate.SFrame.read_csv 函数将 CSV 文件导入 sframe。假设 CSV 文件的内容存储为 'file.csv' 并且 SFrame 的名称是 'sf',使用下面的代码读取 CSV 数据进入一个 SFrame。

        sf = turicreate.SFrame.read_csv('file.csv')

就是这样!!!您也可以对 Graphlab create 执行相同的操作。

请参阅此处的 API 文档:

https://apple.github.io/turicreate/docs/api/generated/turicreate.SFrame.read_csv.html#turicreate.SFrame.read_csv

https://turi.com/products/create/docs/generated/graphlab.SFrame.read_csv.html

【讨论】: