【发布时间】:2020-06-20 15:14:44
【问题描述】:
您好,我正在努力寻找数据集中日期列的最大值和最小值。
下面是我的数据集:
customer_final['tran_date']
0 2014-02-28
1 2014-02-27
2 2014-02-24
3 2014-02-24
4 2014-02-23
...
23048 2011-01-25
23049 2011-01-25
23050 2011-01-25
23051 2011-01-25
23052 2011-01-25
很明显,我们可以在数据集中看到 2011-01-25 之间的数据 至 2014 年 2 月 28 日。
但是执行下面提到的代码给了我错误的输出。
print(customer_final['tran_date'].max())
print(customer_final['tran_date'].min())
2014-12-02 00:00:00
2011-01-02 00:00:00
任何帮助将不胜感激。
编辑:发布原始数据。
transaction_id cust_id tran_date prod_subcat_code prod_cat_code Qty Rate Tax total_amt Store_type
0 80712190438 270351 28-02-2014 1 1 -5 -772 405.300 -4265.300 e-Shop
1 29258453508 270384 27-02-2014 5 3 -5 -1497 785.925 -8270.925 e-Shop
2 51750724947 273420 24-02-2014 6 5 -2 -791 166.110 -1748.110 TeleShop
3 93274880719 271509 24-02-2014 11 6 -3 -1363 429.345 -4518.345 e-Shop
4 51750724947 273420 23-02-2014 6 5 -2 -791 166.110 -1748.110 TeleShop
... ... ... ... ... ... ... ... ... ... ...
23048 94340757522 274550 25-01-2011 12 5 1 1264 132.720 1396.720 e-Shop
23049 89780862956 270022 25-01-2011 4 1 1 677 71.085 748.085 e-Shop
23050 85115299378 271020 25-01-2011 2 6 4 1052 441.840 4649.840 MBR
23051 72870271171 270911 25-01-2011 11 5 3 1142 359.730 3785.730 TeleShop
23052 77960931771 271961 25-01-2011 11 5 1 447 46.935 493.935 TeleShop
编辑 2:DF 中所有列的数据类型。
transaction_id int64
cust_id int64
tran_date datetime64[ns]
prod_subcat_code int64
prod_cat_code int64
Qty int64
Rate int64
Tax float64
total_amt float64
Store_type object
Unnamed: 10 object
dtype: object
【问题讨论】:
-
你的列是日期时间类型的吗?
-
是的,先生!但没有运气。
-
尝试在最大位置获取
customer_final['tran_date'].max(). dt.day,看看你的日期时间类型是否正确。 -
@coc018 是的,它的 dtype 是
datetime64[ns]