python - 过滤条件在熊猫中不起作用
问题描述
我有数据框,其中有一些记录。我通过了一个过滤条件,但它没有给我正确的结果。你能帮我解决这个问题吗?
例子:
东风:
vendor programdate
medforce 3/3/2020
decile 4/3/2020
medforce 8/5/2020
decile 7/23/2020
decile 3/27/2020
我正在通过下面给出的过滤条件:
df1 = df.query("programdate > '3/3/2020'")
它正在打印所有记录。它应该只打印过滤的记录。你能帮我么?
解决方案
你可以这样做:
df1 = df[df.programdate > '3/3/2020']
确保“programdate”是日期时间戳