4

When trying to upload a pivoted dataframe to google sheets using google drive api i'm being prompted with the following error:

TypeError: Setting class 'pandas.core.indexes.multi.MultiIndex' dtype to anything other than object is not supported

Upon checking with dtypes i've seen that my index values were object and i have converted the columns values to oject as well but i'm still getting the error.

import gameData_connection
import pandas as pd
import gspread
from oauth2client.service_account import ServiceAccountCredentials
from df2gspread import df2gspread as d2g

scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('credentials_files.json', scope)
gc = gspread.authorize(credentials)
spreadsheet_key = 'my_spreadsheet_key'
wks_name = 'My File Name'

connection = gameData_connection.getConnection()

print('Connect Succesful')

try:
    with connection.cursor() as cursor:
        sql1 = This is my whole sql query

cursor.execute(sql1)
        df1 = pd.read_sql_query(sql1, connection)
        print('cursor.description:', cursor.description)
        print()

        for row in cursor:
            print(row)

finally:
    connection.close()



table1 = pd.pivot_table(df1, index = ["game", "platform"], 
                        values = ["new_users", "dau", "day1_retention", "day6_retention", "revenue", "arpdau", "arppu", "pau"],
                        columns = ["year_time", "month_time"])


d2g.upload(table1, spreadsheet_key, wks_name, credentials=credentials, row_names=True) 
print(table1)
Out[21]: 
time_join           int64
year_time           int64
month_time          int64
game               object
platform           object
new_users         float64
dau               float64
day1_retention    float64
day6_retention    float64
revenue           float64
arpdau            float64
arppu             float64
pau               float64
dtype: object

I can't figure it out what i'm doing wrong here. If i run d2g.upload(df1, spreadsheet_key, wks_name, credentials=credentials, row_names=True) instead it works so there must be a problem with something happening inside table1.

Please now that if write the same table1 to excel it works.

Thanks in advance for any help

0 Answers0