0

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?

4156
  • 380
  • 4
  • 17

1 Answers1

0

This is a simple solution.

import pygsheets

client = pygsheets.authorize(service_file="cred.json", local=True)
sh = client.open('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))
print(data_filtered)
Dharman
  • 30,962
  • 25
  • 85
  • 135
Ice
  • 170
  • 9