1
我使用转换日期时间列回对象
dftest['date'] = pd.to_datetime(dftest['date'])
现在我想将时间值转换回对象的日期一栏,我转换为datetime64 [NS],所以我可以连接它作为一个字符串。做这个的最好方式是什么?
我使用转换日期时间列回对象
dftest['date'] = pd.to_datetime(dftest['date'])
现在我想将时间值转换回对象的日期一栏,我转换为datetime64 [NS],所以我可以连接它作为一个字符串。做这个的最好方式是什么?
您能够打电话apply
,并使用datetime.strptime
:
In [37]:
df = pd.DataFrame(['05/06/2015 00:00', '22/06/2015 00:00'], columns=['date'])
df['date']= pd.to_datetime(df['date'])
df
Out[37]:
date
0 2015-05-06
1 2015-06-22
In [38]:
df['date'] = df['date'].apply(lambda x: dt.datetime.strftime(x,'%Y-%m-%d'))
df
Out[38]:
date
0 2015-05-06
1 2015-06-22
In [39]:
df.info()
<class 'pandas.core.frame.DataFrame'>
Int64Index: 2 entries, 0 to 1
Data columns (total 1 columns):
date 2 non-null object
dtypes: object(1)
memory usage: 32.0+ bytes