title: Create/Replace a Big Query table with a new one generated by a Cloud Function
body: <p>I am trying to get a table from BQ, transform it into a df, apply modifications to it and then upload it back to BQ replacing the former version.</p>
  
  <p>This function is meant to run as a Google Cloud Function.
  The Service Account that GCS uses has all the authorisations necessary to access BQ.</p>
  
  <p>I have been using this so far but it's not working:</p>
  
  <h3>EXTRACT DFP TABLE FROM BQ</h3>
  
  <pre><code>import google.cloud.bigquery as bigquery
  import pandas_gbq as pd
  
  def execute_function(request):
  
      #Defines Client access &amp; Project to be accessed
      client = bigquery.Client()
  
      SQL = """
      SELECT LINE_ITEM_NAME, TOTAL_LINE_ITEM_LEVEL_CLICKS
      FROM `DATASET.table_imported` 
      WHERE DATE = DATE_ADD(CURRENT_DATE(), INTERVAL -1 DAY)
      AND LINE_ITEM_TYPE = 'PRICE_PRIORITY'
      ORDER BY TOTAL_LINE_ITEM_LEVEL_CLICKS  DESC
      LIMIT 1000"""
  
      query_job = client.query(SQL)
  
      dfp = query_job.result()
  
      ### CREATE WRONG NAMING TABLE SORTED BY CLICKS DESCENDING
  
      dfp = dfp.to_dataframe()
  
      dfp.columns = ['li_name', 'clicks_number']
  
      dfp.set_index('li_name', drop = False, inplace = True)
  
      wrong_naming = pd.DataFrame()
      li_names = []
      clicks_numbers = []
  
      #Adds line items that have names with number of fields not equal to 7 only if not already present
      for row in range(len(dfp)):
          if len(dfp.iloc[row, 0].split('_')) != 7 and dfp.iloc[row, 0] not in li_names:
              li_names.append(dfp.iloc[row, 0])
              clicks_numbers.append(dfp.iloc[row, 1])
  
      #Adds created lists to wrong_naming dataframe
      wrong_naming['li_name'] = li_names
      wrong_naming['clicks_number'] = clicks_numbers
  
      ### EXPORT / SAVE TABLE TO GBQ
  
      wrong_naming.to_gbq('DATA_LAKE_MODELING_US.wrong_naming', 
                          if_exists='replace')
  </code></pre>
  
  <p>But although it worked when I ran the code on my local system, on the cloud it doesn't.</p>
  
  <p>Here´s the error message that I get: "Error: could not handle the request"</p>
  
  <p>Any idea how I can solve this?</p>