Problem : I have an incremental data which I need to append to my google spreadshseet at beginning of each month. Code that I tried :
Trial 1
scope = ['https://spreadsheets.google.com/feeds',
'https://www.googleapis.com/auth/drive']
#creds.json is the credentials file
credentials = ServiceAccountCredentials.from_json_keyfile_name('drd_creds.json', scope)
gd = gc.authorize(credentials)
wks = gd.open_by_key('1lONS0lTy-XXXXXXXXXXX').worksheet("worksheet_name")
set_with_dataframe(worksheet,df_adsets)
The above code doesn't append but overwrites the spreadsheet.
Trial II : As per the guidance given in Appending pandas Data Frame to Google spreadsheet
wks = gd.open_by_key('1lONS0lTy-XXXXXXXXXXX').worksheet("worksheet_name")
existing = get_as_dataframe(wks)
updated = existing.append(df_adsets,sort=True)
set_with_dataframe(wks,updated)
Problem: The method gets all the rows and columns of the spreadsheet (empty ones too as NAN) and when it appends the data there is a weird formatting done for e.g. 1. original value: 23843372759610279 changes to 2.38E+16 2. Column orders are changed to alphabetic order 3. Also, it seems to be a very crude method of getting all the data then appending then writing back.
Is there any function from gspread or any other library to append values/data frame directly rather than overwriting ? (I don't want to write individual rows but just write the whole df from the next empty row).