【问题标题】:Pandas - Remove TimestampPandas - 删除时间戳
【发布时间】:2020-09-02 12:29:09
【问题描述】:

我正在尝试使用 pandas 计算基本统计数据。从 1956 年开始,我有一整年的精确值。我使用 pd.date_range 创建了一个包含全年日期的“日期”列。然后我计算了年份的最大值和最大值的日期。最大值的日期显示“Timestamp('1956-06-19 00:00:00”作为输出。如何仅提取日期。我不需要时间戳或 00:00:00 时间

#Create Date Column
year = 1956
start_date = datetime.date(year,1,1)
end_date = datetime.date(year,12,31)
precip_file["Date"] = pd.date_range(start=start_date,end=end_date,freq="D")

#Yearly maximum value and date of maximum value
yearly_max = precip_file["Precip (mm)"].max(skipna=True)
max_index = precip_file["Precip (mm)"].idxmax()
yearly_max_date = precip_file.iat[max_index,2

Image of output dictionary I am trying to create

【问题讨论】:

    标签: python-3.x pandas datetime


    【解决方案1】:

    可能与this 问题重复,但我不知道您是在尝试转换一个日期时间还是一列日期时间。

    【讨论】:

    • 谢谢,我只需要 .date 参数,因此添加了以下行以仅提取日期。 yearly_max_date = yearly_max_date.date()
    猜你喜欢
    • 1970-01-01
    • 2022-10-14
    • 2014-03-19
    • 2018-09-26
    • 1970-01-01
    • 2011-10-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多