我有以下代码
import pandas as pd
pd.to_datetime(['8/23/1999']).strftime("%m/%d/%Y").astype('str')
这会生成
08/23/1999
但是我想得到
8/23/1999
这种情况有什么特定的格式可以使用吗?
Pandas 支持 Glibc 扩展(参见
man 3 strftime
),因此您可以使用 -
标志。
例如
pd.to_datetime(['8/23/1999']).strftime("%-m/%d/%Y").astype('str')