df2gspread
df2gspread copied to clipboard
type question
When uploading to the Google sheet, all data types are string. How can I save the type?
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.
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.