【发布时间】:2019-07-30 03:58:58
【问题描述】:
我正在使用 Python 3.7.1
我在格式化日期时遇到问题。我必须以月/日/年的格式打印三个值。
我从数据框中获取年份并存储在 temp_year 中,类似地,月份和日期默认为 1。所以我想以 temp_month/1/temp_year 格式打印。
temp_year=(input_df["Indexation Date"].dt.year).iloc[0]
temp_year=temp_year-1
temp_month=(input_df["Indexation Date"].dt.month).iloc[0]
temp_month=temp_month-rpi_lag_months
s="temp_month/temp_year/1"
index_start_date=datetime.strptime(s,"%m/%d/%Y")
我希望输出是:
3/1/2012
但是得到的错误是:
值错误:时间数据“temp_month/temp_year/1”与格式“%m/%d/%Y”不匹配
【问题讨论】:
标签: python