Inexperienced in python here.
I have a pandas
DataFrame
where one of the columns is of type datetime64[ns]
. When attempting to save data to Google Sheets using gspread
, I get an "Object of type Timestamp is not JSON serializable
" error (last line in the code snippet below). The way i understand this, I can change the datetime64[ns]
to string
, and it should theoretically work just fine, however there are some advantages to keeping date/time column as datetime64[ns]
in pandas
DataFrame
. Are there any good ways to dump the data to google sheets without changing data type in data frame? this is my code:
cred = "service_account.json"
url = "https://docs.google.com/spreadsheets/d/xxxxxxxxxxxxxxxxxxxxxxxxxxxxx/edit#gid=0"
course_tm = pd.DataFrame.from_records([s.to_dict() for s in ft_records])
sa = gspread.service_account(filename=cred)
spreadsheet = sa.open_by_url(url)
worksheet = spreadsheet.worksheet("Sheet1")
worksheet.update([course_tm.columns.values.tolist()] + course_tm.values.tolist())
Thank you in advance