How to read data from Google storage cloud to Google cloud datalab

空扰寡人 提交于 2019-12-20 01:43:30

问题


I have a few CSV files storing in Google storage and I want to read those into Google datalab. So far, I have no idea how to do it. I found this and followed the first answer but didn't work and raised

  File "<ipython-input-1-5e9607fa3f65>", line 5
    %%gcs read --object $data_csv --variable data
    ^
SyntaxError: invalid syntax

Any help will be appreciated.


回答1:


If you subtract one of the % symbols it should work. Minimal example:

import google.datalab.storage as storage
import pandas as pd
from io import BytesIO

mybucket = storage.Bucket('BUCKET_NAME')
data_csv = mybucket.object('data.csv')

uri = data_csv.uri
%gcs read --object $uri --variable data

df = pd.read_csv(BytesIO(data))
df.head()


来源:https://stackoverflow.com/questions/48363259/how-to-read-data-from-google-storage-cloud-to-google-cloud-datalab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!