In pygsheets what is the proper way of selecting negative numbers?


I am using pygsheets to make a budget. I want to be able to store all the negative cells in some sort of dictionary (I’m not great with python yet)

I’ve been able to select a DataRange of cells, but how do I add a filter to that?

For example, drange = pygsheets.DataRange(start='A1', worksheet=wks) this is one of my ranges. How would I add a filter to this to only select negative numbers?


This is a simple solution.

import pygsheets

client = pygsheets.authorize(service_file="cred.json", local=True)
sh ='Testing Excel')
wks = sh.sheet1
#This will drag the cell data from range A1:A10 and transform all the string to float
date_unfiltered =[float(*i) for i in wks.get_values(start = "A1", end = "A10")]
#This will filter out all the negative values and return it as a list
data_filtered = list(filter(lambda money: money < 0, date_unfiltered))

Answered By – Ice

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published