OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to search specific columns and return specific values in python using Google spreadsheet?

  • Thread starter Thread starter Sophia Campione
  • Start date Start date
S

Sophia Campione

Guest
I’m having trouble getting this to work. Essentially I want a user to input a keyword and then get a question and answer pair as a return. The first, second, and third columns in the the spreadsheet has the keywords, while the fourth and fifth columns have the question and answer respectively. I want to have it so that the program only searches the first three columns for the keyword, and then only returns the 4th and 5th column from any row that contains that keyword.

So a user will put in the word “VPN”, the program will search the first 3 columns to see if any of them equal VPN. Let’s say the 1st row and 1st column equals VPN, then the program should return the question and answer columns from the first row.

I have code that searches all columns and returns all values from that column, but I’m having trouble with the specific rows and columns portion. Any help would be greatly appreciated!

Code:
scope =["https://spreadsheets.google.com/feeds",'https://www.googleapis.com/auth/spreadsheets',"https://ww$
creds = ServiceAccountCredentials.from_json_keyfile_name("key.json", scope)
client = gspread.authorize(creds)
sheet = client.open("Questionnaire").sheet1

userInput = input('Ask your question: ')

cell = sheet.find(userInput, in_column=[1-3]) #Not sure how to search multiple columns
 
rownum = cell.index(userInput) + 1
row = sheet.row_values(rownum) #Not sure how to return specific columns within this row

if cell != None:
        print(row)
else:
        print("I don't know the answer to that question")

Continue reading...
 

Latest posts

Top