要求:从Google Sheet中按日期检索行,因为Google sheet可以包含具有先前日期的数据
示例:我只需要获取2020年11月9日

目前,我正在使用Pandas从Google Sheet中获取所有行,它工作得很好,但不知道如何才能从google sheet中获取特定的日期过滤器
我试过用pandas的数据框查询方法来过滤?
当我尝试如下所示时,得到了一个错误
df_query='Effective_Date=="2020-11-10"'
df = df.query(self.df_query)
[2020-11-11 01:00:10,603] {taskinstance.py:1145} ERROR - 'the label [Effective_Date=="2020-11-10"] is not in the [index]'
Traceback (most recent call last):
File "/usr/local/lib/python3.6/site-packages/pandas/core/indexing.py", line 1506, in _has_valid_type
error()
File "/usr/local/lib/python3.6/site-packages/pandas/core/indexing.py", line 1501, in error
axis=self.obj._get_axis_name(axis)))
KeyError: 'the label [Effective_Date=="2020-11-10"] is not in the [index]'发布于 2020-11-13 03:00:52
使用Pandas Dataframe解析
df_query='Effective_Date=="2020-11-10"'
df = df.query(self.df_query)
发布于 2020-11-12 03:13:13
假设您的pandas数据框名为df_query,那么下面的代码应该可以工作:
df_filtered = df_query[df_query['Effective_Date']=='2020-11-10']请提供df_query.dtypes和df_query.head(),以防您仍然遇到错误。
https://stackoverflow.com/questions/64759425
复制相似问题