我正在用pygsheets来做预算。我希望能够在某种字典中存储所有的负单元格(我对python还不是很好)
我已经能够选择一个单元格的DataRange,但是如何添加一个过滤器呢?
例如,drange = pygsheets.DataRange(start='A1', worksheet=wks),这是我的范围之一。我如何添加一个过滤器,以只选择负数?
发布于 2022-06-10 03:17:00
这是一个简单的解决方案。
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)https://stackoverflow.com/questions/72568743
复制相似问题