df2gspread icon indicating copy to clipboard operation
df2gspread copied to clipboard

type question

Open soye-jy opened this issue 5 years ago • 2 comments

When uploading to the Google sheet, all data types are string. How can I save the type?

soye-jy avatar Jan 25 '19 06:01 soye-jy

All the changes made to the dataframe gets saved as <class type = 'string'> Exporting this to Google Sheets results in the same datatype. Thus you can use the values of the dataframe regarding it as 'string' datatype.

sauravhiremath avatar Jan 26 '19 15:01 sauravhiremath

You can monkey patch the gspread lib (to not save as strings, via the USER_ENTERED option):

    def upload_pandas_df(self, df):
      values = [df.columns.values.tolist()]
      values.extend(df.values.tolist())
      sheet.values_update(
        self.title,
        params = { 'valueInputOption': 'USER_ENTERED' },
        body = { 'values': values }
      )

    gspread.Worksheet.upload_pandas_df = upload_pandas_df

Or use gspread-dataframe instead.

mroy-seedbox avatar Jun 13 '22 22:06 mroy-seedbox