我有一个如下的数据帧
+-----------+-------+----------+--+--+
| Date | OPP | Result | | |
+-----------+-------+----------+--+--+
| Sat 11/16 | @DAL | L110-102 | | |
+-----------+-------+----------+--+--+
| Wed 11/13 | @POR | W114-106 | | |
+-----------+-------+----------+--+--+
| Mon 11/11 | @LAC | L98-88 | | |
+-----------+-------+----------+--+--+
| Sun 11/10 | @LAL | W113-104 | | |
+-----------+-------+----------+--+--+
| Fri 11/8 | @NO | W122-104 | | |
+-----------+-------+----------+--+--+
| Wed 11/6 | vsSAC | W124-120 | | |
+-----------+-------+----------+--+--+
| Sat 11/2 | @MIL | L115-105 | | |
+-----------+-------+----------+--+--+
我正在尝试筛选日期。你知道吗
这是我试过的,但没有过滤出所有大于11月10日的日期
d1 = d1[(d1['Date'] > 'Sun 11/10')]
更新
我的专栏现在看起来是这样的,我需要能够过滤新的日期并排除“NaT”。尝试d1[(d1['New_Date'] > '2019-11-01')]
但不起作用。你知道吗
0 2019-11-20
1 2019-11-18
2 2019-11-16
3 2019-11-13
4 2019-11-11
5 2019-11-10
6 2019-11-08
7 2019-11-06
8 2019-11-02
9 2019-11-01
10 2019-10-30
11 2019-10-28
12 2019-10-26
13 2019-10-01
14 NaT
15 NaT
16 2019-10-18
17 2019-10-13
18 2019-10-10
19 2019-10-08
20 NaT
21 NaT
任何帮助都将不胜感激。你知道吗
首先,您需要将日期转换为适当的
datetime
对象,提供适当的输入格式(我假设是<weekday> <month>/<day>
—您可以根据datetime
文档https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior对其进行调整)。您可以通过以下方式进行:然后使用python
datetime.strptime()
方法对过滤条件进行类比转换:所以整个例子:
和输出:
(由于没有提供年份,因此假定为
1900
)据我所知,您是否只是为了删除nat而过滤日期?那你就不是这样做的。事实上,熊猫有几个功能可以检查NAT,例如。熊猫.isnull(), 熊猫.notna(), 熊猫.DataFrame.notna()等:
下面是一个如何使用它的快速示例
您是否愿意将格式更改为另一种格式,或者有一个单独的列,列中的日期可供您的critieria搜索?我写了这个解决方案,展示了这条路线,也许它会帮助你的想法,我愿意接受改变的建议:
相关问题 更多 >
编程相关推荐