0

I am trying to insert a number of Dataframes into google spreadsheet. I am using the pygsheets module.

I have a variable that the stores the row number in a loop. I am trying to have the Dataframe inserted in the corresponding cell reference. I am doing as per below but I see the Dataframe gets overwritten in the same cell as it runs through a loop

sheet.set_dataframe(df, 'A' + '1 + x')

My expectations are to insert in the below 3 Dataframes starting from cells A6, A11, A16 respectively. Currently x has a value of 5 and it changes to 10 and 15 respectively as part of the loop.

Kevin Nash
  • 1,511
  • 3
  • 18
  • 37

2 Answers2

1

I dont understand why you are not substituting for x. anyway this will do what you want in py3

sheet.set_dataframe(df, f'A{1+x}')
Nithin
  • 5,470
  • 37
  • 44
  • thanks for the reply this helped. I however am wondering how could I insert 2 empty rows after inserting the values from a Dataframe. I was not able to find any method to insert empty rows, is this something you might be able to help with.. Thanks again.. – Kevin Nash Jan 07 '21 at 04:38
  • you dont need to insert empty rows (assuming they are already empty), just skip then and insert data after two rows. if not empty user clear() to clear specific row – Nithin Jan 07 '21 at 06:52
  • I tried using `clear()` but it threw an error clear not defined. I am trying to have another Dataframe inserted in a loop and hence trying to have a few empty rows in between – Kevin Nash Jan 07 '21 at 07:20
  • sheet.set_dataframe(df, f'A{1+x + 5}') this should add 5 rows offset. this is clear https://pygsheets.readthedocs.io/en/latest/worksheet.html#pygsheets.Worksheet.clear . use the range appropriately. – Nithin Jan 07 '21 at 08:49
0

You can try like this:-

sheet.set_dataframe(df, ('A' + '1 + x'))

I hope this works for you.

Piyush Kumar
  • 120
  • 8