title: Upload Pandas data frame from local machine to Google Cloud bucket
body: <p>I want to upload a pandas data frame from local machine directly to Google Cloud Storage, thus, I am not in a Cloud Function. I tried different ways using <a href="https://stackoverflow.com/questions/36314797/write-a-pandas-dataframe-to-google-cloud-storage-or-bigquery">write-a-pandas-dataframe-to-google-cloud-storage-or-bigquery</a>. But I am not able to save.</p>
  <p><strong>Note: I can use google.cloud package only</strong></p>
  <p>Below is the code I tried</p>
  <pre><code>from google.cloud import storage
  import pandas as pd
  input_dict = [{'Name': 'A', 'Id': 100}, {'Name': 'B', 'Id': 110}, {'Name': 'C', 'Id': 120}]
  df = pd.DataFrame(input_dict)
  </code></pre>
  <p><strong>Try:1</strong></p>
  <pre><code>destination = f'gs://bucket_name/test.csv'
  df.to_csv(destination)
  </code></pre>
  <p><strong>Try:2</strong></p>
  <pre><code>storage_client = storage.Client(project='project')
  bucket = storage_client.get_bucket('bucket_name')
  gs_file = bucket.blob('test.csv')
  df.to_csv(gs_file)
  </code></pre>
  <p>I am getting below errors</p>
  <p>for <strong>option 1</strong> : No such file or directory: 'gs://bucket_name/test.csv'</p>
  <p><strong>option 2</strong>: 'Blob' object has no attribute 'close'</p>
  <p>Thanks,</p>
  <p>Raghunath.</p>