<bdo id='CWRxe'></bdo><ul id='CWRxe'></ul>

  • <small id='CWRxe'></small><noframes id='CWRxe'>

  • <i id='CWRxe'><tr id='CWRxe'><dt id='CWRxe'><q id='CWRxe'><span id='CWRxe'><b id='CWRxe'><form id='CWRxe'><ins id='CWRxe'></ins><ul id='CWRxe'></ul><sub id='CWRxe'></sub></form><legend id='CWRxe'></legend><bdo id='CWRxe'><pre id='CWRxe'><center id='CWRxe'></center></pre></bdo></b><th id='CWRxe'></th></span></q></dt></tr></i><div id='CWRxe'><tfoot id='CWRxe'></tfoot><dl id='CWRxe'><fieldset id='CWRxe'></fieldset></dl></div>
    <legend id='CWRxe'><style id='CWRxe'><dir id='CWRxe'><q id='CWRxe'></q></dir></style></legend>

    1. <tfoot id='CWRxe'></tfoot>

        无法读取上传到谷歌云存储桶的 csv 文件

        Unable to read csv file uploaded on google cloud storage bucket(无法读取上传到谷歌云存储桶的 csv 文件)

        <small id='zWwFg'></small><noframes id='zWwFg'>

        • <bdo id='zWwFg'></bdo><ul id='zWwFg'></ul>

                <tbody id='zWwFg'></tbody>

              <legend id='zWwFg'><style id='zWwFg'><dir id='zWwFg'><q id='zWwFg'></q></dir></style></legend>
              • <tfoot id='zWwFg'></tfoot>

                <i id='zWwFg'><tr id='zWwFg'><dt id='zWwFg'><q id='zWwFg'><span id='zWwFg'><b id='zWwFg'><form id='zWwFg'><ins id='zWwFg'></ins><ul id='zWwFg'></ul><sub id='zWwFg'></sub></form><legend id='zWwFg'></legend><bdo id='zWwFg'><pre id='zWwFg'><center id='zWwFg'></center></pre></bdo></b><th id='zWwFg'></th></span></q></dt></tr></i><div id='zWwFg'><tfoot id='zWwFg'></tfoot><dl id='zWwFg'><fieldset id='zWwFg'></fieldset></dl></div>
                1. 本文介绍了无法读取上传到谷歌云存储桶的 csv 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  Goal - To read csv file uploaded on google cloud storage bucket.

                  Environment - Run Jupyter notebook using SSH instance on Master node. Using python on Jupyter notebook trying to access a simple csv file uploaded onto google cloud storage bucket.

                  Approaches -

                  1st approach - Write a simple python program

                  Wrote following program

                  import csv
                  f = open('gs://python_test_hm/train.csv' , 'rb' ) 
                  csv_f = csv.reader(f)
                  for row in csv_f
                       print row
                  

                  Results - Error message "No such file or directory"

                  2nd Approach - Using gcloud Package tried to access the train.csv file. The sample code is shown below. Below code is not the actual code. The file on google Cloud storage in my version of code was referred to "gs:///Filename.csv" Results - Error message "No such file or directory"

                  Load data from CSV

                  import csv
                  from gcloud import bigquery
                  from gcloud.bigquery import SchemaField
                  client = bigquery.Client()
                  dataset = client.dataset('dataset_name')
                  dataset.create()  # API request
                  
                  SCHEMA = [
                      SchemaField('full_name', 'STRING', mode='required'),
                      SchemaField('age', 'INTEGER', mode='required'),
                   ]
                  table = dataset.table('table_name', SCHEMA)
                  table.create()
                  
                  with open('csv_file', 'rb') as readable:
                      table.upload_from_file(
                          readable, source_format='CSV', skip_leading_rows=1)
                  

                  3rd Approach -

                  import csv
                  import urllib
                  
                  url = 'https://storage.cloud.google.com/<bucket>/train.csv'
                  
                  
                  response = urllib.urlopen(url)
                  cr = csv.reader(response)
                  print cr
                  
                  for row in cr:
                      print row
                  

                  Results - Above code doesn't result in any error but it displays the XML content of the google page as shown below. I am interested in viewing the data of the train csv file.

                  ['<!DOCTYPE html>']
                  ['<html lang="en">']
                  ['  <head>']
                  ['  <meta charset="utf-8">']
                  ['  <meta content="width=300', ' initial-scale=1" name="viewport">']
                  ['  <meta name="google-site-verification" content="LrdTUW9psUAMbh4Ia074-   BPEVmcpBxF6Gwf0MSgQXZs">']
                  ['  <title>Sign in - Google Accounts</title>']
                  

                  Can someone throw some light on what could be possibly wrong here and how do I achieve my goal? Your help is highly appreciated.

                  Thanks so much for your help!

                  解决方案

                  I assume you are using Jupyter notebook running on a machine in Google Cloud Platform (GCP)? If that's the case, you will already have the Google Cloud SDK running on that machine (by default).

                  With this setup you have 2 easy options to work with Google Cloud Storage (GCS):

                  • Use the gcloud/gsutil commands in Jupyter

                    Writing to GCS: gsutil cp train.csv gs://python_test_hm/train.csv

                    Reading from GCS: gsutil cp gs://python_test_hm/train.csv train.csv

                  • Use google-cloud python library

                    Writing to GCS:

                  from google.cloud import storage
                  client = storage.Client()
                  bucket = client.get_bucket('python_test_hm')
                  blob = bucket.blob('train.csv')
                  blob.upload_from_string('this is test content!')
                  

                  Reading from GCS:

                  from google.cloud import storage
                  client = storage.Client()
                  bucket = client.get_bucket('python_test_hm')
                  blob = storage.Blob('train.csv', bucket)
                  content = blob.download_as_string()
                  

                  这篇关于无法读取上传到谷歌云存储桶的 csv 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What happens when you compare 2 pandas Series(当你比较 2 个 pandas 系列时会发生什么)
                  Quickly find differences between two large text files(快速查找两个大文本文件之间的差异)
                  Python - Compare 2 files and output differences(Python - 比较 2 个文件和输出差异)
                  Why do comparisions between very large float values fail in python?(为什么在 python 中非常大的浮点值之间的比较会失败?)
                  Dictionary merge by updating but not overwriting if value exists(字典通过更新合并,但如果值存在则不覆盖)
                  Find entries of one text file in another file in python(在python中的另一个文件中查找一个文本文件的条目)

                    <bdo id='7tfbL'></bdo><ul id='7tfbL'></ul>
                      • <legend id='7tfbL'><style id='7tfbL'><dir id='7tfbL'><q id='7tfbL'></q></dir></style></legend>

                            <tbody id='7tfbL'></tbody>
                          <i id='7tfbL'><tr id='7tfbL'><dt id='7tfbL'><q id='7tfbL'><span id='7tfbL'><b id='7tfbL'><form id='7tfbL'><ins id='7tfbL'></ins><ul id='7tfbL'></ul><sub id='7tfbL'></sub></form><legend id='7tfbL'></legend><bdo id='7tfbL'><pre id='7tfbL'><center id='7tfbL'></center></pre></bdo></b><th id='7tfbL'></th></span></q></dt></tr></i><div id='7tfbL'><tfoot id='7tfbL'></tfoot><dl id='7tfbL'><fieldset id='7tfbL'></fieldset></dl></div>
                          <tfoot id='7tfbL'></tfoot>

                        1. <small id='7tfbL'></small><noframes id='7tfbL'>