我的数据框有一个 DOB
列(示例格式 1/1/2016
)默认情况下会转换为 Pandas dtype ‘object’。
Converting this to date format with df['DOB'] = pd.to_datetime(df['DOB'])
, the date gets converted to: 2016-01-26
and its dtype
is: datetime64[ns]
.
现在我想将此日期格式转换为 01/26/2016
或任何其他通用日期格式。我该怎么做?
(无论我尝试什么方法,它总是以 2016-01-26
格式显示日期。)
原文由 yome 发布,翻译遵循 CC BY-SA 4.0 许可协议
You can use
dt.strftime
if you need to convertdatetime
to other formats (but note that thendtype
of column will beobject
(string
)):