nithinmurali / pygsheets

Google Sheets Python API v4
https://pygsheets.readthedocs.io/en/latest
Other
1.5k stars 220 forks source link

set_dataframe MultiIndex DataFrame to worksheet HttpError 400 returned "Invalid values... #411

Open shadrachbaldon opened 4 years ago

shadrachbaldon commented 4 years ago

Trying to write multi index dataframe to worksheet but getting the following:

raceback (most recent call last):
  File "campaign_link.py", line 99, in <module>
    output_sheet.worksheet('index', 1).set_dataframe(campaign_stats, "A1", fit=True)
  File "/Users/shadrachbaldon/Dev/python/env_leaky_bucket/lib/python3.7/site-packages/pygsheets/utils.py", line 161, in wrapper
    return func(*args, **kwargs)
  File "/Users/shadrachbaldon/Dev/python/env_leaky_bucket/lib/python3.7/site-packages/pygsheets/worksheet.py", line 1366, in set_dataframe
    self.update_values(crange=crange, values=values)
  File "/Users/shadrachbaldon/Dev/python/env_leaky_bucket/lib/python3.7/site-packages/pygsheets/utils.py", line 161, in wrapper
    return func(*args, **kwargs)
  File "/Users/shadrachbaldon/Dev/python/env_leaky_bucket/lib/python3.7/site-packages/pygsheets/worksheet.py", line 669, in update_values
    self.client.sheet.values_batch_update(self.spreadsheet.id, body, parse)
  File "/Users/shadrachbaldon/Dev/python/env_leaky_bucket/lib/python3.7/site-packages/pygsheets/sheet.py", line 304, in values_batch_update
    self._execute_requests(request)
  File "/Users/shadrachbaldon/Dev/python/env_leaky_bucket/lib/python3.7/site-packages/pygsheets/sheet.py", line 359, in _execute_requests
    response = request.execute(num_retries=self.retries)
  File "/Users/shadrachbaldon/Dev/python/env_leaky_bucket/lib/python3.7/site-packages/googleapiclient/_helpers.py", line 130, in positional_wrapper
    return wrapped(*args, **kwargs)
  File "/Users/shadrachbaldon/Dev/python/env_leaky_bucket/lib/python3.7/site-packages/googleapiclient/http.py", line 856, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://sheets.googleapis.com/v4/spreadsheets/1rLh-ffXSLjTnZtTk8FQ5qh6M1i2SCeKgLPqp47dC9x0/values/test%21A1%3AY2084?valueInputOption=USER_ENTERED&alt=json returned "Invalid values[0][6]: list_value {
  values {
    string_value: "December"
  }
  values {
    string_value: "Leads"
  }
}">

DataFrame info:

 #   Column                                  Non-Null Count  Dtype  
---  ------                                  --------------  -----  
 0   Campaign                                5267 non-null   object 
 1   Campaign status                         5267 non-null   object 
 2   Currency code                           5267 non-null   object 
 3   Budget                                  5267 non-null   object 
 4   Budget type                             5267 non-null   object 
 5   Cost                                    5267 non-null   float64
 6   (December, Leads)                       0 non-null      object 
 7   (December, Cost Per Lead)               0 non-null      object 
 8   (December, Approved)                    0 non-null      object 
 9   (December, Cost Per Approved)           0 non-null      object 
 10  (December, Deals In Progress)           0 non-null      object 
 11  (December, Cost Per Deals In Progress)  0 non-null      object 
 12  (January, Leads)                        0 non-null      object 
 13  (January, Cost Per Lead)                0 non-null      object 
 14  (January, Approved)                     0 non-null      object 
 15  (January, Cost Per Approved)            0 non-null      object 
 16  (January, Deals In Progress)            0 non-null      object 
 17  (January, Cost Per Deals In Progress)   0 non-null      object 
 18  (February, Leads)                       0 non-null      object 
 19  (February, Cost Per Lead)               0 non-null      object 
 20  (February, Approved)                    0 non-null      object 
 21  (February, Cost Per Approved)           0 non-null      object 
 22  (February, Deals In Progress)           0 non-null      object 
 23  (February, Cost Per Deals In Progress)  0 non-null      object 
dtypes: float64(1), object(23)
ldsalomone commented 4 years ago

Did you try resetting the index before writing the dataframe?