【发布时间】:2015-04-27 03:19:07
【问题描述】:
我有一个 csv 文件,我读入了 pandas 数据框。日期和时间列在“日期时间”列中。我想找到最近和最近的日期来创建索引以创建时间序列图。 pandas 有没有返回最近日期和最近日期的函数?
编辑:
我已经尝试过使用最小值和最大值。他们给出不正确的答案。
>>> f['Start Date']
Trip ID
4576 8/29/2013 14:13
4607 8/29/2013 14:42
4130 8/29/2013 10:16
4251 8/29/2013 11:29
4299 8/29/2013 12:02
4927 8/29/2013 18:54
4500 8/29/2013 13:25
4563 8/29/2013 14:02
4760 8/29/2013 17:01
4258 8/29/2013 11:33
4549 8/29/2013 13:52
4498 8/29/2013 13:23
4965 8/29/2013 19:32
4557 8/29/2013 13:57
4386 8/29/2013 12:31
...
198757 2/28/2014 20:40
198760 2/28/2014 20:59
198761 2/28/2014 20:59
198763 2/28/2014 21:32
198764 2/28/2014 21:32
198765 2/28/2014 21:34
198766 2/28/2014 21:41
198767 2/28/2014 21:50
198768 2/28/2014 21:54
198770 2/28/2014 22:19
198771 2/28/2014 22:15
198772 2/28/2014 22:38
198773 2/28/2014 22:45
198774 2/28/2014 23:01
198775 2/28/2014 23:20
Name: Start Date, Length: 144015, dtype: object
>>> min(f['Start Date'])
'1/1/2014 0:14'
>>> max(f['Start Date'])
'9/9/2013 9:59'
【问题讨论】:
-
您可以在 pandas 系列中使用 python
min和max函数。这应该可以得到你想要的。 -
如果您正在查看图形功能,您还可以查看pandas.pydata.org/pandas-docs/dev/timeseries.html