Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python GSpread – Loop through rows

I am trying to loop through the rows on a Google sheet using python and gspread. Every time I try to get the values, the list is returned as columns and not rows.

Is there a way to retrieve the rows and loop through them?

Looking here https://docs.gspread.org/en/latest/user-guide.html#getting-all-values-from-a-row-or-a-column I am not too sure how many rows there will be. Is there a way to count the first column?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Import, Authenticate and Open the Sheet as defined by the gspread documentation:

import gspread
gc = gspread.service_account()
worksheet = gc.open("Sheet1").sheet1

Then use .get_all_values() to iterate through the rows:

rows = worksheet.get_all_values()
for row in rows:
   # ...
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading