Python Forum
Iterate through google sheet
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Iterate through google sheet
#1
Hi!

I am using some salesforce script to get gsheet data and insert it into salesforce.

My problem is how to proper iterate through my cells.

Im connecting with gspread.
# Authorise your Notebook
gc = gspread.authorize(credentials)
# The sprad sheet ID, which can be taken from the link to the sheet
spreadsheet_key = 'xxx'
sheet = gc.open_by_url('https://docs.google.com/spreadsheets/d/url')
worksheet = sheet.get_worksheet(1)
data = worksheet.get_all_values()
headers = data.pop(0)
df = pd.DataFrame(data, columns=headers)
Frame has 48 columns. I want to prepare a function which inserts values from column nr 44 and column nr 30. I have for my tests 10 rows.

My idea is to create simple loop, sth like this:

#for c in range(worksheet.ncols):
#    for r in range(worksheet.nrows):
for c in range(ncol?): 
    for r in  range(nrow?): 
        Subject = 'test subject'
        Type: 'Note'
        Description = worksheet.ol_values(2,r)[0] --I have no idea here, need to use column nr 30
        print(Description)
        Owner = worksheet.ol_values(2,r)[0] -- I have no idea here, need to use column nr 44
        print(Owner)
        --sf insert function--
Any help appreciated! I'm using gsheets for the first time.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question Python + Google Sheet | Best way to update specific cells in a single Update()? Vokofe 1 2,670 Dec-16-2020, 05:26 AM
Last Post: Vokofe
  how to import files in Google Collab wihout downloading them to PC and to Google Disk sveto4ka 9 3,866 Jun-03-2020, 12:40 PM
Last Post: sveto4ka
  Excel: Apply formating of a sheet(file1) to another sheet(file2) lowermoon 1 2,033 May-26-2020, 07:57 AM
Last Post: buran
  iterate read data from excel sheet jp2017 1 2,321 Jun-19-2019, 07:45 PM
Last Post: micseydel
  Blockspring Trello export to Google Sheet Shafla 0 2,186 Apr-10-2019, 09:21 PM
Last Post: Shafla
  Code Wireless Temperature sensor and send sensor readings to google sheet jenkins43 0 2,190 Nov-29-2018, 12:44 PM
Last Post: jenkins43
  inserting photos in 1 sheet of a 6 sheet excel file fails Pedroski55 0 2,373 Mar-03-2018, 01:53 AM
Last Post: Pedroski55

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020