I'm importing data from a Google Sheets spreadsheet, but I need to filter some rows and not load all of them. Does anyone run this library, and know if there is an argument to filter rows.
I am doing it as follows so far:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope=['https://spreadsheets.google.com/feeds']
creds=ServiceAccountCredentials.from_json_keyfile_name('Python- cbe875b7fd9f.json', scope)
client=gspread.authorize(creds)
sheet=client.open('Prueba Python').sheet1
preventivos=sheet.get_all_records()
print(preventivos)
I do this because there is a column that has several options for example "NOGO", "MOC" and "AHM" option. I want to import only those rows that have the "AHM" option. In this way the load will be faster since now it takes several seconds and there is a lot of data that I am not interested in importing.
Example file:
https://docs.google.com/spreadsheets/d/1PWKujfqoMpdecMWNxGRxPQoA4RtmZeMVBemH6rXfVF8/edit#gid=0
Jorge, the documentation of this library indicates for the routine
get_all_records()
:That is, a list of dictionaries where each key is the column header. Something like the following, based on your example:
I did not transcribe all the records, you must also see the behavior against columns without headers, for example the one that would be the column
H
of your spreadsheet. With these data the filter is something like this:That is, we return the rows where in the "SOURCE" column we find the text "AHM".