Python 3.x 从xlsx文件查询日期范围和产品大小

Python 3.x 从xlsx文件查询日期范围和产品大小,python-3.x,pandas,where-clause,Python 3.x,Pandas,Where Clause,我正在使用Python3.6来实现这一点。下面是我感兴趣的几个重要专栏 Auto-Gen Index : Product Container : Ship Date :....... 0 : Large Box : 2017-01-09:....... 1 : Large Box : 2012-07-15:....... 2 : Small Box : 2012-

我正在使用Python3.6来实现这一点。下面是我感兴趣的几个重要专栏

 Auto-Gen Index : Product Container : Ship Date :.......
    0           :   Large Box       : 2017-01-09:.......
    1           :   Large Box       : 2012-07-15:.......
    2           :   Small Box       : 2012-07-18:.......
    3           :   Large Box       : 2012-07-31:.......
我想查询指示大箱子作为其产品容器且装运日期必须在2012年7月期间的行

 file_name = r'''Sample-Superstore-Subset-Excel.xlsx'''
 df = read_excel(file_name, sheet_name = my_sheet)
 lb = df.loc[df['Product Container'] == 'Large Box'] //Get large box
 july = lb[(lb['Ship Date'] > '2012-07-01') & (lb['Ship Date'] < '2012-07-31')]
file_name=r''Sample-Superstore-Subset-Excel.xlsx''
df=读取excel(文件名、工作表名=我的工作表)
lb=df.loc[df['Product Container']=='Large Box']//获取大箱子
7月=lb[(lb[‘装运日期’]>‘2012-07-01’)和(lb[‘装运日期’]<‘2012-07-31’)]

我只是想知道如何使用python的查询和where条件(pd.query())?

如果您的问题是何时使用
loc
vs
where
,请参阅我的答案:

loc
视为一个过滤器-只给我df中需要的部分 符合条件

其中
最初来自numpy。它在数组上运行并检查 每个元素都符合一个条件。所以它会返回整个阵列, 结果或结果。where的一个很好的特性是,您还可以获得 支持不同的东西,例如df2=df.where(df['Goals']>10, other='0'),将不满足条件的值替换为0

如果您询问何时使用
查询
,恐怕除了性能之外,没有其他真正的理由。如果您有一个非常大的数据集,那么查询速度会更快。有关高级性能的更多信息。

请注意,Python使用
#
作为注释,而不是
/