gpt4 book ai didi

python - 如何从数据框中的日期时间列中查找日期范围?

转载 作者:行者123 更新时间:2023-12-04 12:05:07 26 4
gpt4 key购买 nike

想知道如何打印数据框中的日期范围。似乎这很简单,但我在任何地方都找不到答案。有没有一种简单的方法可以使用 pandas datetime 模块来做到这一点?
因此,如果这是数据框的小版本,例如:


日期
ID
值(value)


2020-09-23 14:00:00
4752764
12212

2020-10-25 08:00:00
4752764
12298

2020-10-28 12:00:00
4752764
12291

2020-10-29 18:00:00
4752764
12295


我怎么能得到这样的输出:

date_range = 2020-09-23 to 2020-10-29
date_range = 23rd of September, 2020 to 29th of October, 2020
我很感激任何答案:)

最佳答案

尝试这个

df['Date'] = pd.to_datetime(df['Date']) # If your Date column is of the type object otherwise skip this
date_range = str(df['Date'].dt.date.min()) + ' to ' +str(df['Date'].dt.date.max())

关于python - 如何从数据框中的日期时间列中查找日期范围?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65349787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com