【发布时间】:2022-03-09 08:55:02
【问题描述】:
这是我在数据集 01/04/2021 中的原始日期,格式为日/月/年。 当我使用 pandas 时间戳 将日期转换为月份名称和日期名称时,它会将 12。 例如 2021 年 1 月 4 日 - 月 - 1 月 13/04/2021 - 月 - 四月。
代码
for attacks in df['Create Date/Time']:
event_date.append(pd.Timestamp(attacks).day)
event_month.append(pd.Timestamp(attacks).month_name())
event_year.append (pd.Timestamp(attacks).year)
event_day.append(pd.Timestamp(attacks).day_name())
combined_time.append(pd.Timestamp(attacks).ctime())
【问题讨论】:
-
这能回答你的问题吗? stackoverflow.com/questions/37625334/…
-
不要循环,使用
pandas.to_datetime和dayfirst=False转换整个Series -
我的意思是
dayfirst=True...